分配的Java堆栈在哪里? [英] where is the Java stack allocated?

查看:86
本文介绍了分配的Java堆栈在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网站上注意到以下内容:JVM HotSpot内存分为3个内存空间:

I have noted the following from a website: The JVM HotSpot memory is split between 3 memory spaces:


  • Java堆

  • PermGen(永久代)空间

  • 原生堆(C-Heap)

在hotSpot JVM中分配的堆栈在哪里?在本机堆中?

Where is the stack allocated in hotSpot JVM? In native heap?

更新:
另一个参考信息:
对于64位VM,C-Heap容量=物理服务器总RAM &安培;虚拟内存 - Java堆 - PermGen

update: another reference info: For a 64-bit VM, the C-Heap capacity = Physical server total RAM & virtual memory – Java Heap - PermGen

推荐答案

答案是:


  1. 这是依赖于实现的。

  1. It is implementation dependent.

在我看到的实现中,线程堆栈分配由标准处理C本机线程库,它看起来像是要去操作系统为堆栈分配一个内存段。所以以上都不是。

In the implementation I looked at, the thread stack allocation was handled by the standard C native thread library, and it looked like the library was going to the OS to allocate a memory segment for the stack. So "none of the above".

您可以通过深入研究与您的平台相关的OpenJDK源代码来确认这一点。

You can confirm this by delving into the OpenJDK source code relevant to your platform.

更新

从旧问题来看,这是来自 pthread_create 的代码片段,用于请求分配线程堆栈。此方法由JVM线程实现使用来创建本机线程。

From an old question, here is the snippet of code from pthread_create that requests the allocation of the thread stack. This method used by the JVM thread implementation to create the native thread.

 mmap(0, attr.__stacksize, 
     PROT_READ|PROT_WRITE|PROT_EXEC, 
     MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)

如您所见,它只是使用 mmap 系统调用来从操作系统请求内存段。正如我在评论中所说,这不是常规Java堆,不是Permgen堆,也不是C本机堆。它是操作系统特别请求的一段内存。

As you can see, it just uses the mmap system call to request a memory segment from the operating system. As I said in a comment, this is NOT the regular Java heap, NOT the Permgen heap, and NOT the C native heap. It is a segment of memory specifically requested from the operating system.

作为参考,这里是 mmap系统调用手册输入


更新:另一个参考信息:对于64位VM,C-Heap容量=物理服务器总RAM&虚拟内存 - Java堆 - PermGen

update: another reference info: For a 64-bit VM, the C-Heap capacity = Physical server total RAM & virtual memory – Java Heap - PermGen

IMO,这是一个过于简单化的过程。 (并且请提供您在何处找到此信息的链接...以便我们可以以原始形式阅读。)

IMO, that is an oversimplification. (And please provide a link to where you found this information ... so that we can read it in its original form.)

这篇关于分配的Java堆栈在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆