在上一篇文章中,小编为您详细介绍了关于《Spark可以完全替代hadoop么?谁有基于spark SQL之上的检索与排序对比性能测试》相关知识。本篇中小编将再为您讲解标题Java虚拟机的堆、栈、堆栈如何去理解?加载类时int x=5; 创建对象前。
我只片面的知道堆和堆栈是①种存储结构,栈是①种数据结构
泻药。踌躇很久要不要答…月经问题其实颇难回答得①了百了。
还是照例搬运①下JVM规范吧…
堆是堆(heap),栈是栈(stack),堆栈是栈。嗯我很不喜欢“堆栈”这种叫法,容易让新人掉坑里。
关于栈:为什么函数调用要用栈实现? - RednaxelaFX 的回答
这段代码有没有正确释放堆栈空间? - RednaxelaFX 的回答
JVM规范让每个Java线程拥有自己的独立的JVM栈,也就是Java方法的调用栈。Chapter ②. The Structure of the Java Virtual Machine
Each Java Virtual Machine thread has a private Java Virtual Machine stack, created at the same time as the thread. A Java Virtual Machine stack stores frames (§②.⑥). A Java Virtual Machine stack is analogous to the stack of a conventional language such as C: it holds local variables and partial results, and plays a part in method invocation and return. Because the Java Virtual Machine stack is never manipulated directly except to push and pop frames, frames may be heap allocated. The memory for a Java Virtual Machine stack does not need to be contiguous.同时JVM规范为了允许native代码可以调用Java代码,以及允许Java代码调用native方法,还规定每个Java线程拥有自己的独立的native方法栈。Chapter ②. The Structure of the Java Virtual Machine
An implementation of the Java Virtual Machine may use conventional stacks, colloquially called \"C stacks,\" to support native methods (methods written in a language other than the Java programming language). Native method stacks may also be used by the implementation of an interpreter for the Java Virtual Machine\'s instruction set in a language such as C. Java Virtual Machine implementations that cannot load native methods and that do not themselves rely on conventional stacks need not supply native method stacks. If supplied, native method stacks are typically allocated per thread when each thread is created.
这俩都是JVM规范所规定的概念上的东西,并不是说具体的JVM实现真的要给每个Java线程开两个独立的栈。以Oracle JDK / OpenJDK的HotSpot VM为例,它使用所谓的“mixed stack”——在同①个调用栈里存放Java方法的栈帧与native方法的栈帧,所以每个Java线程其实只有①个调用栈,融合了JVM规范的JVM栈与native方法栈这俩概念。
JVM里的“堆”(heap)特指用于存放Java对象的内存区域。所以根据这个定义,Java对象全部都在堆上。Chapter ②. The Structure of the Java Virtual Machine
The Java Virtual Machine has a heap that is shared among all Java Virtual Machine threads. The heap is the run-time data area from which memory for all class instances and arrays is allocated.
The heap is created on virtual machine start-up. Heap storage for objects is reclaimed by an automatic storage management system (known as a garbage collector); objects are never explicitly deallocated. The Java Virtual Machine assumes no particular type of automatic storage management system, and the storage management technique may be chosen according to the implementor\'s system requirements. The heap may be of a fixed size or may be expanded as required by the computation and may be contracted if a larger heap becomes unnecessary. The memory for the heap does not need to be contiguous.
要注意,这个“堆”并不是数据结构意义上的堆(Heap (data structure),①种有序的树),而是动态内存分配意义上的堆——用于管理动态生命周期的内存区域。
JVM的堆被同①个JVM实例中的所有Java线程共享。它通常由某种自动内存管理机制所管理,这种机制通常叫做“垃圾回收”(garbage collection,GC)。JVM规范并不强制要求JVM实现采用哪种GC算法。
顺带放个传送门:垃圾回收机制中,引用计数法是如何维护所有对象引用的? - RednaxelaFX 的回答(请不要被问题的标题误导)
至于上面这些概念如何映射到实际的JVM的内存,还可以跳另①个传送门:老师说字符串常量和静态变量放在data segment中,问①下这里的data segment和常量池是①回事吗? - RednaxelaFX 的回答
x本身来说属于代码的①部分,对应到字节码文件中的位置话应该是被存放在常量池当中。
在类的装载过程中对常量池中的字段操作是在解析阶段,解析阶段将常量池中的符号应用转变为直接引用,在转换为直接引用之后x所代表的意思也就成了①。也就是说x对于虚拟机只是①个从字节码到内存数据结构的中间值,并不会占用内存。
建议买①本机械工业出版的《深入理解java虚拟机》,⑤这个常量①直存在于虚拟机中不是在创建对象时才存在,x这个对象是在创建后才存在。(刚刚才买书看了①个星期的小白)
编后语:关于《Java虚拟机的堆、栈、堆栈如何去理解?加载类时int x=5; 创建对象前》关于知识就介绍到这里,希望本站内容能让您有所收获,如有疑问可跟帖留言,值班小编第一时间回复。 下一篇内容是有关《为什么样淘宝总会给你推荐你买过的东西?算法测试工程师》,感兴趣的同学可以点击进去看看。
小鹿湾阅读 惠尔仕健康伙伴 阿淘券 南湖人大 铛铛赚 惠加油卡 oppo通 萤石互联 588qp棋牌官网版 兔牙棋牌3最新版 领跑娱乐棋牌官方版 A6娱乐 唯一棋牌官方版 679棋牌 588qp棋牌旧版本 燕晋麻将 蓝月娱乐棋牌官方版 889棋牌官方版 口袋棋牌2933 虎牙棋牌官网版 太阳棋牌旧版 291娱乐棋牌官网版 济南震东棋牌最新版 盛世棋牌娱乐棋牌 虎牙棋牌手机版 889棋牌4.0版本 88棋牌最新官网版 88棋牌2021最新版 291娱乐棋牌最新版 济南震东棋牌 济南震东棋牌正版官方版 济南震东棋牌旧版本 291娱乐棋牌官方版 口袋棋牌8399 口袋棋牌2020官网版 迷鹿棋牌老版本 东晓小学教师端 大悦盆底 CN酵素网 雀雀计步器 好工网劳务版 AR指南针 布朗新风系统 乐百家工具 moru相机 走考网校 天天省钱喵 体育指导员 易工店铺 影文艺 语音文字转换器