Java-Direct | heap support to replace portions
kandi X-RAY | Java-Direct Summary
kandi X-RAY | Java-Direct Summary
JEP with off heap support to replace portions of Unsafe and other sun.* methods.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Java-Direct
Java-Direct Key Features
Java-Direct Examples and Code Snippets
Community Discussions
Trending Discussions on Java-Direct
QUESTION
According to various sources (though not specifically mentioned in JavaDoc), ByteBuffer.allocateDirect
allocates the memory off the main JVM heap. I can confirm that using Java Mission Control, seeing that the program that calls ByteBuffer n = ByteBuffer.allocateDirect(Integer.MAX_VALUE)
does not use much of Java Heap memory:
However, this off-heap memory allocation stops working when one limits JVM heap memory. For example, when I run the JVM with -Xmx1g
option, the allocateDirect
call causes the following exception: Exception in thread "main" java.lang.OutOfMemoryError: Direct buffer memory
. I do not fully understand how can this JVM option pertain to off-heap direct memory allocation, as - according to the documentation - the -Xmx
option sets the Java heap space size. If I allocate the memory using getUnsafe().allocateMemory(Integer.MAX_VALUE);
the memory is allocated successfully. My JVM is as follows:
java version "10" 2018-03-20 Java(TM) SE Runtime Environment 18.3 (build 10+46) Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10+46, mixed mode)
Is this kind of behaviour between Xmx
and ByteBuffer.allocateDirect
expected?
EDIT: There seemed to be a (non-reproducible) bug in JDK 1.7 with the same behaviour as described above. So is this a bug?
...ANSWER
Answered 2018-May-24 at 01:00Well, this is not a bug, let me tell you why the allocateDirect
causes OOM
.
In JVM, you already know -Xmx
option that sets the Max JVM Heap Size. But you have to know that JVM Memory(heap) is also a part of your PC memory.
In simple terms, this means Your PC Memory
= JVM
+ Direct Memory
.
So when you set JVM option to '-Xmx1g' and get OOM
exception, check be sure you have enough memory(the rest of your PC memory) to run allocateDirect
.
Hope it will help you!
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Java-Direct
You can use Java-Direct like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the Java-Direct component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page