From 2c97d8fb44cf5db0be72be9ffcc2c7e52cfa4278 Mon Sep 17 00:00:00 2001 From: Xueming Shen Date: Wed, 16 Feb 2011 11:11:31 -0800 Subject: [PATCH 1/3] 6999337: java.exe fails to start if some directory names in path to java binaries contain Russian characters Updated to make sure the system properties are accessable by vm during initialization Reviewed-by: alanb, mchung --- jdk/src/share/classes/java/lang/System.java | 32 ++++++++++++--------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/jdk/src/share/classes/java/lang/System.java b/jdk/src/share/classes/java/lang/System.java index 59e15ee1d04..3eafd1b3cbb 100644 --- a/jdk/src/share/classes/java/lang/System.java +++ b/jdk/src/share/classes/java/lang/System.java @@ -1102,6 +1102,18 @@ public final class System { * Initialize the system class. Called after thread initialization. */ private static void initializeSystemClass() { + + // VM might invoke JNU_NewStringPlatform() to set those encoding + // sensitive properties (user.home, user.name, boot.class.path, etc.) + // during "props" initialization, in which it may need access, via + // System.getProperty(), to the related system encoding property that + // have been initialized (put into "props") at early stage of the + // initialization. So make sure the "props" is available at the + // very beginning of the initialization and all system properties to + // be put into it directly. + props = new Properties(); + initProperties(props); // initialized by the VM + // There are certain system configurations that may be controlled by // VM options such as the maximum amount of direct memory and // Integer cache size used to support the object identity semantics @@ -1112,7 +1124,12 @@ public final class System { // // See java.lang.Integer.IntegerCache and the // sun.misc.VM.saveAndRemoveProperties method for example. - props = initSystemProperties(); + // + // Save a private copy of the system properties object that + // can only be accessed by the internal implementation. Remove + // certain system properties that are not intended for public access. + sun.misc.VM.saveAndRemoveProperties(props); + lineSeparator = props.getProperty("line.separator"); sun.misc.Version.init(); @@ -1123,7 +1140,6 @@ public final class System { setIn0(new BufferedInputStream(fdIn)); setOut0(new PrintStream(new BufferedOutputStream(fdOut, 128), true)); setErr0(new PrintStream(new BufferedOutputStream(fdErr, 128), true)); - // Load the zip library now in order to keep java.util.zip.ZipFile // from trying to use itself to load this library later. loadLibrary("zip"); @@ -1151,18 +1167,6 @@ public final class System { setJavaLangAccess(); } - private static Properties initSystemProperties() { - Properties props = new Properties(); - initProperties(props); // initialized by the VM - - // Save a private copy of the system properties object that - // can only be accessed by the internal implementation. Remove - // certain system properties that are not intended for public access. - sun.misc.VM.saveAndRemoveProperties(props); - - return props; - } - private static void setJavaLangAccess() { // Allow privileged classes outside of java.lang sun.misc.SharedSecrets.setJavaLangAccess(new sun.misc.JavaLangAccess(){ From 313991183b716ea420c2a2155ada03191faca6b7 Mon Sep 17 00:00:00 2001 From: Stuart Marks Date: Wed, 16 Feb 2011 18:22:52 -0800 Subject: [PATCH 2/3] 7018392: update URLJarFile.java to use try-with-resources Reviewed-by: alanb, chegar, hawtin --- .../sun/net/www/protocol/jar/URLJarFile.java | 42 +++++++------------ 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/jdk/src/share/classes/sun/net/www/protocol/jar/URLJarFile.java b/jdk/src/share/classes/sun/net/www/protocol/jar/URLJarFile.java index 36acd9cc381..f32141d5030 100644 --- a/jdk/src/share/classes/sun/net/www/protocol/jar/URLJarFile.java +++ b/jdk/src/share/classes/sun/net/www/protocol/jar/URLJarFile.java @@ -27,6 +27,9 @@ package sun.net.www.protocol.jar; import java.io.*; import java.net.*; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; import java.util.*; import java.util.jar.*; import java.util.zip.ZipFile; @@ -208,38 +211,23 @@ public class URLJarFile extends JarFile { JarFile result = null; /* get the stream before asserting privileges */ - final InputStream in = url.openConnection().getInputStream(); - - try { + try (final InputStream in = url.openConnection().getInputStream()) { result = AccessController.doPrivileged( new PrivilegedExceptionAction() { public JarFile run() throws IOException { - OutputStream out = null; - File tmpFile = null; + Path tmpFile = Files.createTempFile("jar_cache", null); try { - tmpFile = File.createTempFile("jar_cache", null); - tmpFile.deleteOnExit(); - out = new FileOutputStream(tmpFile); - int read = 0; - byte[] buf = new byte[BUF_SIZE]; - while ((read = in.read(buf)) != -1) { - out.write(buf, 0, read); - } - out.close(); - out = null; - return new URLJarFile(tmpFile, closeController); - } catch (IOException e) { - if (tmpFile != null) { - tmpFile.delete(); - } - throw e; - } finally { - if (in != null) { - in.close(); - } - if (out != null) { - out.close(); + Files.copy(in, tmpFile, StandardCopyOption.REPLACE_EXISTING); + JarFile jarFile = new URLJarFile(tmpFile.toFile(), closeController); + tmpFile.toFile().deleteOnExit(); + return jarFile; + } catch (Throwable thr) { + try { + Files.delete(tmpFile); + } catch (IOException ioe) { + thr.addSuppressed(ioe); } + throw thr; } } }); From e5d4746fb471416a7b89f6c7d2e70b172def494a Mon Sep 17 00:00:00 2001 From: Chris Hegarty Date: Thu, 17 Feb 2011 09:56:38 +0000 Subject: [PATCH 3/3] 7017901: OOME in java/util/concurrent/BlockingQueue/CancelledProducerConsumerLoops.java Unbounded queues should be disabled in the test Reviewed-by: alanb --- .../BlockingQueue/CancelledProducerConsumerLoops.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jdk/test/java/util/concurrent/BlockingQueue/CancelledProducerConsumerLoops.java b/jdk/test/java/util/concurrent/BlockingQueue/CancelledProducerConsumerLoops.java index 34f0722d8bd..755ff9c2d97 100644 --- a/jdk/test/java/util/concurrent/BlockingQueue/CancelledProducerConsumerLoops.java +++ b/jdk/test/java/util/concurrent/BlockingQueue/CancelledProducerConsumerLoops.java @@ -124,11 +124,11 @@ public class CancelledProducerConsumerLoops { oneRun(new ArrayBlockingQueue(CAPACITY), pairs, iters); oneRun(new LinkedBlockingQueue(CAPACITY), pairs, iters); oneRun(new LinkedBlockingDeque(CAPACITY), pairs, iters); - oneRun(new LinkedTransferQueue(), pairs, iters); oneRun(new SynchronousQueue(), pairs, iters / 8); - /* PriorityBlockingQueue is unbounded + /* unbounded queue implementations are prone to OOME oneRun(new PriorityBlockingQueue(iters / 2 * pairs), pairs, iters / 4); + oneRun(new LinkedTransferQueue(), pairs, iters); */ }