Skip to content

Apache Lucene open-source search software

LUCENE-3867: Remove useless catch block, print more diagnotic information (32 bit HVMs never suppoort OBJECT_ALIGNMENT detection)

Uwe Schindler3a29e80f31dc
diff --git a/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java b/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java
index 377db0f85b2..eaf23dd2bdf 100644
--- a/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java
+++ b/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java
@@ -37,10 +37,10 @@ public final class RamUsageEstimator {
* JVM diagnostic features.
*/
public static enum JvmFeature {
- OBJECT_REFERENCE_SIZE("Object reference size estimated using array index scale."),
- ARRAY_HEADER_SIZE("Array header size estimated using array based offset."),
- FIELD_OFFSETS("Shallow instance size based on field offsets."),
- OBJECT_ALIGNMENT("Object alignment retrieved from HotSpotDiagnostic MX bean.");
+ OBJECT_REFERENCE_SIZE("Object reference size estimated using array index scale"),
+ ARRAY_HEADER_SIZE("Array header size estimated using array based offset"),
+ FIELD_OFFSETS("Shallow instance size based on field offsets"),
+ OBJECT_ALIGNMENT("Object alignment retrieved from HotSpotDiagnostic MX bean");
public final String description;
@@ -219,17 +219,11 @@ public final class RamUsageEstimator {
beanClazz
);
final Method getVMOptionMethod = beanClazz.getMethod("getVMOption", String.class);
- try {
- final Object vmOption = getVMOptionMethod.invoke(hotSpotBean, "ObjectAlignmentInBytes");
- objectAlignment = Integer.parseInt(
- vmOption.getClass().getMethod("getValue").invoke(vmOption).toString()
- );
- supportedFeatures.add(JvmFeature.OBJECT_ALIGNMENT);
- } catch (InvocationTargetException ite) {
- if (!(ite.getCause() instanceof IllegalArgumentException))
- throw ite;
- // ignore the error completely and use default of 8 (32 bit JVMs).
- }
+ final Object vmOption = getVMOptionMethod.invoke(hotSpotBean, "ObjectAlignmentInBytes");
+ objectAlignment = Integer.parseInt(
+ vmOption.getClass().getMethod("getValue").invoke(vmOption).toString()
+ );
+ supportedFeatures.add(JvmFeature.OBJECT_ALIGNMENT);
} catch (Exception e) {
// Ignore.
}
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.java b/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.java
index 862313aa52a..a19c5a70318 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.java
@@ -89,10 +89,16 @@ public class TestRamUsageEstimator extends LuceneTestCase {
public void testReferenceSize() {
if (!isSupportedJVM()) {
System.err.println("WARN: Your JVM does not support certain Oracle/Sun extensions.");
- System.err.println(" Memory estimates may be inaccurate.");
- System.err.println(" Please report this to the Lucene mailing list. JVM version: " + RamUsageEstimator.JVM_INFO_STRING);
+ System.err.println(" Memory estimates may be inaccurate.");
+ System.err.println(" Please report this to the Lucene mailing list.");
+ System.err.println("JVM version: " + RamUsageEstimator.JVM_INFO_STRING);
+ System.err.println("UnsupportedFeatures:");
for (JvmFeature f : RamUsageEstimator.getUnsupportedFeatures()) {
- System.err.println(" - " + f.toString());
+ System.err.print(" - " + f.toString());
+ if (f == RamUsageEstimator.JvmFeature.OBJECT_ALIGNMENT) {
+ System.err.print("; Please note: 32bit Oracle/Sun VMs don't allow exact OBJECT_ALIGNMENT retrieval, this is a known issue.");
+ }
+ System.err.println();
}
}