Log Message
XStream will now detect a working enhanced mode dynamically instead using lists of known vendors (JIRA:XSTR-723).
Modified Paths
Diff
Modified: trunk/xstream/src/java/com/thoughtworks/xstream/core/JVM.java (2025 => 2026)
--- trunk/xstream/src/java/com/thoughtworks/xstream/core/JVM.java 2013-02-28 01:14:38 UTC (rev 2025)
+++ trunk/xstream/src/java/com/thoughtworks/xstream/core/JVM.java 2013-02-28 01:28:58 UTC (rev 2026)
@@ -18,6 +18,7 @@
import com.thoughtworks.xstream.core.util.WeakCache;
import java.lang.reflect.Field;
+import java.lang.reflect.Method;
import java.security.AccessControlException;
import java.text.AttributedString;
import java.text.ParseException;
@@ -39,6 +40,7 @@
private final boolean supportsSwing = loadClass("javax.swing.LookAndFeel", false) != null;
private final boolean supportsSQL = loadClass("java.sql.Date") != null;
+ private static final boolean canAllocateWithUnsafe;
private static final boolean optimizedTreeSetAddAll;
private static final boolean optimizedTreeMapPutAll;
private static final boolean canParseUTCDateFormat;
@@ -49,13 +51,33 @@
private static final float DEFAULT_JAVA_VERSION = 1.4f;
+ static class Broken {
+ Broken() {
+ throw new UnsupportedOperationException();
+ }
+ }
+
static {
+ boolean test = true;
+ try {
+ Class unsafeClass = Class.forName("sun.misc.Unsafe");
+ Field unsafeField = unsafeClass.getDeclaredField("theUnsafe");
+ unsafeField.setAccessible(true);
+ Object unsafe = unsafeField.get(null);
+ Method allocateInstance = unsafeClass.getDeclaredMethod("allocateInstance", new Class[]{Class.class});
+ allocateInstance.setAccessible(true);
+ test = allocateInstance.invoke(unsafe, new Object[]{Broken.class}) != null;
+ } catch (Exception e) {
+ test = false;
+ } catch (Error e) {
+ test = false;
+ }
+ canAllocateWithUnsafe = test;
Comparator comparator = new Comparator() {
public int compare(Object o1, Object o2) {
throw new RuntimeException();
}
};
- boolean test = true;
SortedMap map = new PresortedMap(comparator);
map.put("one", null);
map.put("two", null);
@@ -133,34 +155,10 @@
return majorJavaVersion >= 1.8f;
}
- private static boolean isSun() {
- return vendor.indexOf("Sun") != -1;
- }
-
- private static boolean isOracle() {
- return vendor.indexOf("Oracle") != -1;
- }
-
- private static boolean isApple() {
- return vendor.indexOf("Apple") != -1;
- }
-
- private static boolean isHPUX() {
- return vendor.indexOf("Hewlett-Packard Company") != -1;
- }
-
private static boolean isIBM() {
return vendor.indexOf("IBM") != -1;
}
- private static boolean isBlackdown() {
- return vendor.indexOf("Blackdown") != -1;
- }
-
- private static boolean isDiablo() {
- return vendor.indexOf("FreeBSD Foundation") != -1;
- }
-
/**
* @since 1.4
*/
@@ -168,53 +166,6 @@
return vendor.indexOf("Android") != -1;
}
- /*
- * Support for sun.misc.Unsafe and sun.reflect.ReflectionFactory is present
- * in JRockit versions R25.1.0 and later, both 1.4.2 and 5.0 (and in future
- * 6.0 builds).
- */
- private static boolean isBEAWithUnsafeSupport() {
- // This property should be "BEA Systems, Inc."
- if (vendor.indexOf("BEA") != -1) {
-
- /*
- * Recent 1.4.2 and 5.0 versions of JRockit have a java.vm.version
- * string starting with the "R" JVM version number, i.e.
- * "R26.2.0-38-57237-1.5.0_06-20060209..."
- */
- String vmVersion = System.getProperty("java.vm.version");
- if (vmVersion.startsWith("R")) {
- /*
- * We *could* also check that it's R26 or later, but that is
- * implicitly true
- */
- return true;
- }
-
- /*
- * For older JRockit versions we can check java.vm.info. JRockit
- * 1.4.2 R24 -> "Native Threads, GC strategy: parallel" and JRockit
- * 5.0 R25 -> "R25.2.0-28".
- */
- String vmInfo = System.getProperty("java.vm.info");
- if (vmInfo != null) {
- // R25.1 or R25.2 supports Unsafe, other versions do not
- return (vmInfo.startsWith("R25.1") || vmInfo
- .startsWith("R25.2"));
- }
- }
- // If non-BEA, or possibly some very old JRockit version
- return false;
- }
-
- private static boolean isHitachi() {
- return vendor.indexOf("Hitachi") != -1;
- }
-
- private static boolean isSAP() {
- return vendor.indexOf("SAP AG") != -1;
- }
-
public Class loadClass(String name) {
return loadClass(name, true);
}
@@ -251,15 +202,12 @@
reflectionProvider = (ReflectionProvider) cls.newInstance();
}
}
- if (reflectionProvider == null) {
- reflectionProvider = new PureJavaReflectionProvider();
- }
} catch (InstantiationException e) {
- reflectionProvider = new PureJavaReflectionProvider();
} catch (IllegalAccessException e) {
- reflectionProvider = new PureJavaReflectionProvider();
} catch (AccessControlException e) {
// thrown when trying to access sun.misc package in Applet context.
+ }
+ if (reflectionProvider == null) {
reflectionProvider = new PureJavaReflectionProvider();
}
}
@@ -267,18 +215,7 @@
}
private boolean canUseSun14ReflectionProvider() {
- return (isSun()
- || isOracle()
- || isApple()
- || isHPUX()
- || isIBM()
- || isBlackdown()
- || isBEAWithUnsafeSupport()
- || isHitachi()
- || isSAP()
- || isDiablo())
- && is14()
- && loadClass("sun.misc.Unsafe") != null;
+ return canAllocateWithUnsafe && is14();
}
public static boolean reverseFieldDefinition() {
@@ -359,7 +296,11 @@
JVM jvm = new JVM();
System.out.println("XStream JVM diagnostics");
System.out.println("java.specification.version: " + System.getProperty("java.specification.version"));
+ System.out.println("java.specification.vendor: " + System.getProperty("java.specification.vendor"));
+ System.out.println("java.specification.name: " + System.getProperty("java.specification.name"));
System.out.println("java.vm.vendor: " + vendor);
+ System.out.println("java.vendor: " + System.getProperty("java.vendor"));
+ System.out.println("java.vm.name: " + System.getProperty("java.vm.name"));
System.out.println("Version: " + majorJavaVersion);
System.out.println("XStream support for enhanced Mode: " + jvm.canUseSun14ReflectionProvider());
System.out.println("Supports AWT: " + jvm.supportsAWT());
Modified: trunk/xstream-distribution/src/content/changes.html (2025 => 2026)
--- trunk/xstream-distribution/src/content/changes.html 2013-02-28 01:14:38 UTC (rev 2025)
+++ trunk/xstream-distribution/src/content/changes.html 2013-02-28 01:28:58 UTC (rev 2026)
@@ -38,7 +38,18 @@
<ul>
</ul>
-->
+ <h1 id="upcoming">Upcoming</h1>
+ <p>Not yet released.</p>
+
+ <h2>Major changes</h2>
+
+ <ul>
+ <li>JIRA:XSTR-723: XStream will now detect a working enhanced mode dynamically instead using lists of known
+ vendors. This allows enhanced support for JamVM if it is bundled with OpenJDK. It will currently fail on a
+ runtime based on GNU Classpath (at least up to version 0.98).</li>
+ </ul>
+
<h1 id="1.4.4">1.4.4</h1>
<p>Released 19. January 2013.</p>
Modified: trunk/xstream-distribution/src/content/faq.html (2025 => 2026)
--- trunk/xstream-distribution/src/content/faq.html 2013-02-28 01:14:38 UTC (rev 2025)
+++ trunk/xstream-distribution/src/content/faq.html 2013-02-28 01:28:58 UTC (rev 2026)
@@ -51,11 +51,10 @@
<!-- ...................................................... -->
<h2 id="Compatibility_enhanced_mode_jvm">Which JVMs allow XStream to operate in enhanced mode?</h2>
- <p>Currently on the Sun, Apple, HP, IBM and Blackdown 1.4 JVMs and onwards.
- Also for Hitachi, SAP and Diablo from 1.5 and onwards.
- Support for BEA JRockit starting with R25.1.0.
- OpenJDK 6 is also supported.
- For all other JVMs, XStream should be used in pure Java mode.</p>
+ <p>Since XStream 1.4.5 XStream will check a working enhanced mode dynamically. However, enhanced mode is known to
+ be working on the Sun, Apple, HP, IBM and Blackdown 1.4 JVMs and onwards, for Hitachi, SAP and Diablo from 1.5 and
+ onwards, for BEA JRockit starting with R25.1.0 and for OpenJDK. Note, that an active SecurityManager might prevent
+ the usage of the enhanced mode also.</p>
<!-- ...................................................... -->
<h2 id="Compatibility_enhanced_mode_advantage">What are the advantages of using enhanced mode over pure Java mode?</h2>
To unsubscribe from this list please visit:
