estimateMaxDirectMemory() — netty Function Reference
Architecture documentation for the estimateMaxDirectMemory() function in PlatformDependent.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 5a915619_2268_5b50_46c5_9b521ab8b6c7["estimateMaxDirectMemory()"] 2e66d079_807f_6785_864f_73ab09fbc515["PlatformDependent"] 5a915619_2268_5b50_46c5_9b521ab8b6c7 -->|defined in| 2e66d079_807f_6785_864f_73ab09fbc515 style 5a915619_2268_5b50_46c5_9b521ab8b6c7 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
common/src/main/java/io/netty/util/internal/PlatformDependent.java lines 1474–1533
@SuppressWarnings("unchecked")
public static long estimateMaxDirectMemory() {
long maxDirectMemory = PlatformDependent0.bitsMaxDirectMemory();
if (maxDirectMemory > 0) {
return maxDirectMemory;
}
try {
// Now try to get the JVM option (-XX:MaxDirectMemorySize) and parse it.
// Note that we are using reflection because Android doesn't have these classes.
ClassLoader systemClassLoader = getSystemClassLoader();
Class<?> mgmtFactoryClass = Class.forName(
"java.lang.management.ManagementFactory", true, systemClassLoader);
Class<?> runtimeClass = Class.forName(
"java.lang.management.RuntimeMXBean", true, systemClassLoader);
MethodHandles.Lookup lookup = MethodHandles.publicLookup();
MethodHandle getRuntime = lookup.findStatic(
mgmtFactoryClass, "getRuntimeMXBean", methodType(runtimeClass));
MethodHandle getInputArguments = lookup.findVirtual(
runtimeClass, "getInputArguments", methodType(List.class));
List<String> vmArgs = (List<String>) getInputArguments.invoke(getRuntime.invoke());
Pattern maxDirectMemorySizeArgPattern = getMaxDirectMemorySizeArgPattern();
for (int i = vmArgs.size() - 1; i >= 0; i --) {
Matcher m = maxDirectMemorySizeArgPattern.matcher(vmArgs.get(i));
if (!m.matches()) {
continue;
}
maxDirectMemory = Long.parseLong(m.group(1));
switch (m.group(2).charAt(0)) {
case 'k': case 'K':
maxDirectMemory *= 1024;
break;
case 'm': case 'M':
maxDirectMemory *= 1024 * 1024;
break;
case 'g': case 'G':
maxDirectMemory *= 1024 * 1024 * 1024;
break;
default:
break;
}
break;
}
} catch (Throwable ignored) {
// Ignore
}
if (maxDirectMemory <= 0) {
maxDirectMemory = Runtime.getRuntime().maxMemory();
logger.debug("maxDirectMemory: {} bytes (maybe)", maxDirectMemory);
} else {
logger.debug("maxDirectMemory: {} bytes", maxDirectMemory);
}
return maxDirectMemory;
}
Domain
Subdomains
Source
Frequently Asked Questions
What does estimateMaxDirectMemory() do?
estimateMaxDirectMemory() is a function in the netty codebase, defined in common/src/main/java/io/netty/util/internal/PlatformDependent.java.
Where is estimateMaxDirectMemory() defined?
estimateMaxDirectMemory() is defined in common/src/main/java/io/netty/util/internal/PlatformDependent.java at line 1474.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free