diff --git a/core/src/main/java/org/elasticsearch/env/NodeEnvironment.java b/core/src/main/java/org/elasticsearch/env/NodeEnvironment.java index 86b6b704a72d1..93e95dfaa96fd 100644 --- a/core/src/main/java/org/elasticsearch/env/NodeEnvironment.java +++ b/core/src/main/java/org/elasticsearch/env/NodeEnvironment.java @@ -296,10 +296,10 @@ private void maybeLogPathDetails() throws IOException { } private void maybeLogHeapDetails() { - ByteSizeValue maxHeapSize = JvmInfo.jvmInfo().getMem().getHeapMax(); - Boolean usingCompressedOops = JvmInfo.jvmInfo().usingCompressedOops(); - String usingCompressedOopsStatus = usingCompressedOops == null ? "unknown" : Boolean.toString(usingCompressedOops); - logger.info("heap size [{}], compressed ordinary object pointers [{}]", maxHeapSize, usingCompressedOopsStatus); + JvmInfo jvmInfo = JvmInfo.jvmInfo(); + ByteSizeValue maxHeapSize = jvmInfo.getMem().getHeapMax(); + String useCompressedOops = jvmInfo.useCompressedOops(); + logger.info("heap size [{}], compressed ordinary object pointers [{}]", maxHeapSize, useCompressedOops); } private static String toString(Collection items) { diff --git a/core/src/main/java/org/elasticsearch/monitor/jvm/JvmInfo.java b/core/src/main/java/org/elasticsearch/monitor/jvm/JvmInfo.java index 8e1fb9ba7db9a..82a99bd0bd11c 100644 --- a/core/src/main/java/org/elasticsearch/monitor/jvm/JvmInfo.java +++ b/core/src/main/java/org/elasticsearch/monitor/jvm/JvmInfo.java @@ -116,11 +116,10 @@ public class JvmInfo implements Streamable, ToXContent { Method vmOptionMethod = clazz.getMethod("getVMOption", String.class); Object useCompressedOopsVmOption = vmOptionMethod.invoke(hotSpotDiagnosticMXBean, "UseCompressedOops"); Method valueMethod = vmOptionClazz.getMethod("getValue"); - String value = (String)valueMethod.invoke(useCompressedOopsVmOption); - info.usingCompressedOops = Boolean.parseBoolean(value); + info.useCompressedOops = (String)valueMethod.invoke(useCompressedOopsVmOption); } catch (Throwable t) { // unable to deduce the state of compressed oops - // usingCompressedOops will hold its default value of null + info.useCompressedOops = "unknown"; } INSTANCE = info; @@ -157,7 +156,7 @@ public static JvmInfo jvmInfo() { String[] gcCollectors = Strings.EMPTY_ARRAY; String[] memoryPools = Strings.EMPTY_ARRAY; - private Boolean usingCompressedOops; + private String useCompressedOops; private JvmInfo() { } @@ -282,8 +281,16 @@ public Map getSystemProperties() { return this.systemProperties; } - public Boolean usingCompressedOops() { - return this.usingCompressedOops; + /** + * The value of the JVM flag UseCompressedOops, if available otherwise + * "unknown". The value "unknown" indicates that an attempt was + * made to obtain the value of the flag on this JVM and the attempt + * failed. + * + * @return the value of the JVM flag UseCompressedOops or "unknown" + */ + public String useCompressedOops() { + return this.useCompressedOops; } @Override @@ -307,7 +314,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.field(Fields.GC_COLLECTORS, gcCollectors); builder.field(Fields.MEMORY_POOLS, memoryPools); - builder.field(Fields.USING_COMPRESSED_OOPS, usingCompressedOops == null ? "unknown" : Boolean.toString(usingCompressedOops)); + builder.field(Fields.USING_COMPRESSED_OOPS, useCompressedOops); builder.endObject(); return builder; @@ -368,11 +375,7 @@ public void readFrom(StreamInput in) throws IOException { mem.readFrom(in); gcCollectors = in.readStringArray(); memoryPools = in.readStringArray(); - if (in.readBoolean()) { - usingCompressedOops = in.readBoolean(); - } else { - usingCompressedOops = null; - } + useCompressedOops = in.readString(); } @Override @@ -397,12 +400,7 @@ public void writeTo(StreamOutput out) throws IOException { mem.writeTo(out); out.writeStringArray(gcCollectors); out.writeStringArray(memoryPools); - if (usingCompressedOops != null) { - out.writeBoolean(true); - out.writeBoolean(usingCompressedOops); - } else { - out.writeBoolean(false); - } + out.writeString(useCompressedOops); } public static class Mem implements Streamable {