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

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1304564 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2012-03-23 19:11:31 +00:00
parent 7291d38535
commit 3a29e80f31
2 changed files with 18 additions and 18 deletions

View File

@ -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.
}

View File

@ -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();
}
}