src/share/classes/sun/misc/VM.java

Print this page
rev 9786 : 8022854: System.setProperties(null) causes implementation private properties to reappear
Reviewed-by: alanb, mchung

*** 187,197 **** // private static long directMemory = 64 * 1024 * 1024; // Returns the maximum amount of allocatable direct buffer memory. // The directMemory variable is initialized during system initialization ! // in the saveAndRemoveProperties method. // public static long maxDirectMemory() { return directMemory; } --- 187,197 ---- // private static long directMemory = 64 * 1024 * 1024; // Returns the maximum amount of allocatable direct buffer memory. // The directMemory variable is initialized during system initialization ! // in the saveVMSystemProperties method. // public static long maxDirectMemory() { return directMemory; }
*** 199,209 **** // aligned. The "-XX:+PageAlignDirectMemory" option can be used to force // buffers, allocated by ByteBuffer.allocateDirect, to be page aligned. private static boolean pageAlignDirectMemory; // Returns {@code true} if the direct buffers should be page aligned. This ! // variable is initialized by saveAndRemoveProperties. public static boolean isDirectMemoryPageAligned() { return pageAlignDirectMemory; } /** --- 199,209 ---- // aligned. The "-XX:+PageAlignDirectMemory" option can be used to force // buffers, allocated by ByteBuffer.allocateDirect, to be page aligned. private static boolean pageAlignDirectMemory; // Returns {@code true} if the direct buffers should be page aligned. This ! // variable is initialized by saveVMSystemProperties. public static boolean isDirectMemoryPageAligned() { return pageAlignDirectMemory; } /**
*** 219,232 **** * system initialization time. This method should only be used * for the system properties that are not changed during runtime. * 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()) throw new IllegalStateException("Should be non-empty if initialized"); --- 219,228 ----
*** 236,261 **** // TODO: the Property Management needs to be refactored and // the appropriate prop keys need to be accessible to the // 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) { if (booted) throw new IllegalStateException("System initialization has completed"); savedProps.putAll(props); // Set the maximum amount of direct memory. This value is controlled // by the vm option -XX:MaxDirectMemorySize=<size>. // 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"); if (s != null) { if (s.equals("-1")) { // -XX:MaxDirectMemorySize not given, take default directMemory = Runtime.getRuntime().maxMemory(); } else { --- 232,261 ---- // TODO: the Property Management needs to be refactored and // the appropriate prop keys need to be accessible to the // calling classes to avoid duplication of keys. private static final Properties savedProps = new Properties(); ! /** ! * 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 // by the vm option -XX:MaxDirectMemorySize=<size>. // 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 = savedProps.getProperty("sun.nio.MaxDirectMemorySize"); if (s != null) { if (s.equals("-1")) { // -XX:MaxDirectMemorySize not given, take default directMemory = Runtime.getRuntime().maxMemory(); } else {
*** 264,286 **** directMemory = l; } } // Check if direct buffers should be page aligned ! s = (String)props.remove("sun.nio.PageAlignDirectMemory"); ! if ("true".equals(s)) ! pageAlignDirectMemory = true; - // Remove other private system properties // used by java.lang.Integer.IntegerCache ! props.remove("java.lang.Integer.IntegerCache.high"); // used by java.util.zip.ZipFile ! props.remove("sun.zip.disableMemoryMapping"); // used by sun.launcher.LauncherHelper ! props.remove("sun.java.launcher.diag"); } // Initialize any miscellenous operating system settings that need to be // set for the class libraries. // --- 264,305 ---- directMemory = l; } } // Check if direct buffers should be page aligned ! 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"); // used by java.lang.Integer.IntegerCache ! sanitized.remove("java.lang.Integer.IntegerCache.high"); // used by java.util.zip.ZipFile ! sanitized.remove("sun.zip.disableMemoryMapping"); // used by sun.launcher.LauncherHelper ! sanitized.remove("sun.java.launcher.diag"); ! ! return sanitized; } // Initialize any miscellenous operating system settings that need to be // set for the class libraries. //