Skip to content

Commit

Permalink
Simpler using compressed oops flag representation
Browse files Browse the repository at this point in the history
This commit modifies the internal representation of the JVM flag
UseCompressedOops to just be a String. This means we can just store the
value of the flag or "unknown" directly so that we do not have to engage
in shenanigans with three-valued logic around a boxed boolean.

Relates #15489
  • Loading branch information
jasontedor committed Dec 17, 2015
1 parent 9a1133c commit 028b206
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
8 changes: 4 additions & 4 deletions core/src/main/java/org/elasticsearch/env/NodeEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> items) {
Expand Down
34 changes: 16 additions & 18 deletions core/src/main/java/org/elasticsearch/monitor/jvm/JvmInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
}
Expand Down Expand Up @@ -282,8 +281,16 @@ public Map<String, String> 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
Expand All @@ -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;
Expand Down Expand Up @@ -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.readOptionalString();
}

@Override
Expand All @@ -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.writeOptionalString(useCompressedOops);
}

public static class Mem implements Streamable {
Expand Down

0 comments on commit 028b206

Please sign in to comment.