gpt4 book ai didi

java - Java 元空间和 native 内存的区别

转载 作者:搜寻专家 更新时间:2023-10-31 08:09:44 25 4
gpt4 key购买 nike

MetaspaceNative memory 有什么区别?

可以使用 jconsole、jvisualvm、jstat cmds 跟踪元空间。
似乎可以使用 jcmd 跟踪 native 内存。 Link

元空间也是 native 内存吗?

NIO 缓冲区存储在哪里?在元空间或 native 内存中?

最佳答案

元空间也是 native 内存吗?

Yes, Metaspace is part of the Native Memory(process memory) and is limited by host operating system

source http://karunsubramanian.com/websphere/one-important-change-in-memory-management-in-java-8/您可以使用 jmap -permstat PID 对其进行监控。如果您的应用程序最终在元空间中分配了大量内存,那么它将影响整个系统,而不仅仅是 JVM。这就是为什么它建议您使用 -XX:MetaspaceSize 来显式为您的应用设置最大元空间大小。

Java NIO APIs use ByteBuffers as the source and destination of I/O calls, and come in two flavours:

  • Heap Byte Buffer (wrap a byte[] array, allocated in the garbage collected Java heap)
  • Direct Byte Buffer (wrap memory allocated outside the Java heap )

Since only "native" memory can be passed to operating system calls, so it won't be moved by the garbage collector, it means that when you use a heap ByteBuffer for I/O, it is copied into a temporary direct ByteBuffer. The JDK caches one temporary buffer per thread, without any memory limits (i.e. an unbounded cache). As a result, if you call I/O methods with large heap ByteBuffers from multiple threads, your process can use a huge amount of additional native memory.

可以引用this & this article了解更多详情。

已更新

RSS=OffHeap(映射文件、JVM 内部代码(.bss 段)、线程堆栈、直接缓冲区)+ GC 内部结构+ 堆 + 本地库(例如 IO 库)使用和分配的结构+ 元空间 + JVM 的共享库 + CodeCache

你可以在 linux 上使用 pmap -x分析 JVM 进程的内存映射。此外,Jemalloc通过设置适当的 MALLOC_CONF env variables 可以帮助在每 x GB/x kB 的内存分配/堆栈跟踪之后将配置文件写入磁盘.生成文件后,请尝试使用
Jeprof visualisation .例如。

 jeprof --show_bytes --pdf `which w` jeprof.heap > sample.pdf

为调用图生成 PDF。

关于java - Java 元空间和 native 内存的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39675406/

25 4 0
文章推荐: javascript - jQuery - 如何将一些带有文本的标签元素移动到最近的 div
文章推荐: ios - 为什么渐变不覆盖 View 的整个宽度
搜寻专家
个人简介

我是一名优秀的程序员,十分优秀!

滴滴打车优惠券免费领取
滴滴打车优惠券
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com