From d117bfb14957c752b4d6be2fc311ad8d535f3b34 Mon Sep 17 00:00:00 2001 From: David Lim Date: Fri, 23 Aug 2019 02:22:41 -0600 Subject: [PATCH] Handle exception thrown in log while trying to call sun.misc.VM.maxDirectMemory() which is not available in Java 11 (#8352) * handle exception thrown while trying to call sun.misc.VM.maxDirectMemory() which is not available in Java 11 * fixup String.format -> StringUtils.format --- .../java/org/apache/druid/cli/GuiceRunnable.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/services/src/main/java/org/apache/druid/cli/GuiceRunnable.java b/services/src/main/java/org/apache/druid/cli/GuiceRunnable.java index 8407351cf26..58229375226 100644 --- a/services/src/main/java/org/apache/druid/cli/GuiceRunnable.java +++ b/services/src/main/java/org/apache/druid/cli/GuiceRunnable.java @@ -25,6 +25,7 @@ import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.Module; import org.apache.druid.initialization.Initialization; +import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.java.util.common.lifecycle.Lifecycle; import org.apache.druid.java.util.common.logger.Logger; import org.apache.druid.server.log.StartupLoggingConfig; @@ -78,12 +79,20 @@ public abstract class GuiceRunnable implements Runnable final Lifecycle lifecycle = injector.getInstance(Lifecycle.class); final StartupLoggingConfig startupLoggingConfig = injector.getInstance(StartupLoggingConfig.class); + Long directSizeBytes = null; + try { + directSizeBytes = JvmUtils.getRuntimeInfo().getDirectMemorySizeBytes(); + } + catch (UnsupportedOperationException ignore) { + // querying direct memory is not supported + } + log.info( - "Starting up with processors[%,d], memory[%,d], maxMemory[%,d], directMemory[%,d].", + "Starting up with processors[%,d], memory[%,d], maxMemory[%,d]%s.", JvmUtils.getRuntimeInfo().getAvailableProcessors(), JvmUtils.getRuntimeInfo().getTotalHeapSizeBytes(), JvmUtils.getRuntimeInfo().getMaxHeapSizeBytes(), - JvmUtils.getRuntimeInfo().getDirectMemorySizeBytes() + directSizeBytes != null ? StringUtils.format(", directMemory[%,d]", directSizeBytes) : "" ); if (startupLoggingConfig.isLogProperties()) {