--- old/src/share/classes/sun/misc/VM.java 2014-04-23 19:14:12.090741486 -0700 +++ new/src/share/classes/sun/misc/VM.java 2014-04-23 19:14:11.918741478 -0700 @@ -189,7 +189,7 @@ // Returns the maximum amount of allocatable direct buffer memory. // The directMemory variable is initialized during system initialization - // in the saveAndRemoveProperties method. + // in the saveVMSystemProperties method. // public static long maxDirectMemory() { return directMemory; @@ -201,7 +201,7 @@ private static boolean pageAlignDirectMemory; // Returns {@code true} if the direct buffers should be page aligned. This - // variable is initialized by saveAndRemoveProperties. + // variable is initialized by saveVMSystemProperties. public static boolean isDirectMemoryPageAligned() { return pageAlignDirectMemory; } @@ -221,10 +221,6 @@ * It accesses a private copy of the system properties so * that user's locking of the system properties object will not * cause the library to deadlock. - * - * Note that the saved system properties do not include - * the ones set by sun.misc.Version.init(). - * */ public static String getSavedProperty(String key) { if (savedProps.isEmpty()) @@ -238,14 +234,18 @@ // calling classes to avoid duplication of keys. private static final Properties savedProps = new Properties(); - // Save a private copy of the system properties and remove - // the system properties that are not intended for public access. - // - // This method can only be invoked during system initialization. - public static void saveAndRemoveProperties(Properties props) { + /** + * Save a private copy of the system properties. + * + * @implNote This method can only be invoked during system initialization. + */ + public static void saveVMSystemProperties(Properties props) { if (booted) throw new IllegalStateException("System initialization has completed"); + if (!savedProps.isEmpty()) + throw new IllegalStateException("Properties already initialized"); + savedProps.putAll(props); // Set the maximum amount of direct memory. This value is controlled @@ -253,7 +253,7 @@ // The maximum amount of allocatable direct buffer memory (in bytes) // from the system property sun.nio.MaxDirectMemorySize set by the VM. // The system property will be removed. - String s = (String)props.remove("sun.nio.MaxDirectMemorySize"); + String s = savedProps.getProperty("sun.nio.MaxDirectMemorySize"); if (s != null) { if (s.equals("-1")) { // -XX:MaxDirectMemorySize not given, take default @@ -266,19 +266,38 @@ } // Check if direct buffers should be page aligned - s = (String)props.remove("sun.nio.PageAlignDirectMemory"); - if ("true".equals(s)) - pageAlignDirectMemory = true; + s = savedProps.getProperty("sun.nio.PageAlignDirectMemory"); + pageAlignDirectMemory = Boolean.parseBoolean(s); + + } + + /** + * Returns a copy of the saved system properties with private implementation + * properties removed. + * + * @return a newly created Properties instance containing only sanitized + */ + public static Properties getSanitizedSavedProperties() { + Properties sanitized = new Properties(); + + sanitized.putAll(savedProps); + + // Remove implementation private system properties + + sanitized.remove("sun.nio.MaxDirectMemorySize"); + + sanitized.remove("sun.nio.PageAlignDirectMemory"); - // Remove other private system properties // used by java.lang.Integer.IntegerCache - props.remove("java.lang.Integer.IntegerCache.high"); + sanitized.remove("java.lang.Integer.IntegerCache.high"); // used by java.util.zip.ZipFile - props.remove("sun.zip.disableMemoryMapping"); + sanitized.remove("sun.zip.disableMemoryMapping"); // used by sun.launcher.LauncherHelper - props.remove("sun.java.launcher.diag"); + sanitized.remove("sun.java.launcher.diag"); + + return sanitized; } // Initialize any miscellenous operating system settings that need to be