Initialization & clean up
Initialization & clean up java
1. Where storage lives
1.1. Registers
This is the fastest storage because it exists in a place different from that of other storage: inside the processor. However, the number of registers is severely limited, so registers are allocated as they are needed. You don‘t have direct control, nor do you see any evidence in your programs that registers even exist (C & C++, on the other hand, allow you to suggest register allocation to the compiler).
1.2. The stack
This lives in the general random-access memory (RAM) area, but has direct support from the processor via its stack pointer. The stack pointer is moved down to create new
memory and moved up to release that memory. This is an extremely fast and efficient way to allocate storage, second only to registers. The Java system must know, while it is creating the program, the exact lifetime of all the items that are stored on the stack. This constraint places limits on the flexibility of your programs, so while some Java storage exists on the stack—in particular, object references—Java objects themselves are not placed on the stack.
1.3. The heap
This is a general-purpose pool of memory (also in the RAM area) where all Java objects live. The nice thing about the heap is that, unlike the stack, the compiler doesn‘t need to know how long that storage must stay on the heap. Thus, there‘s a great deal of flexibility in using storage on the heap. Whenever you need an object, you simply write the code to create it by using new, and the storage is allocated on the heap when that code is executed. Of course there‘s a price you pay for this flexibility: It may take more time to allocate and clean up heap storage than stack storage (if you even could create objects on the stack in Java, as you can in C++).
1.4. Constant storage
Constant values are often placed directly in the program code, which is safe since they can never change. Sometimes constants are cordoned off by themselves so that they can be optionally placed in read-only memory (ROM), in embedded systems.
1.5. Non-RAM storage
If data lives completely outside a program, it can exist while the program is not running, outside the control of the program. The two primary examples of this are streamed objects, in which objects are turned into streams of bytes, generally to be sent to another machine, and persistent objects, in which the objects are placed on disk so they will hold their state even when the program is terminated. The trick with these types of storage is turning the objects into something that can exist on the other medium, and yet can be resurrected into
Initialization & clean up java
a regular RAM based object when necessary. Java provides support for lightweight
persistence, and mechanisms such as JDBC and Hibernate provide more sophisticated support for storing and retrieving object information in databases.
1.6. Static storage
Static means in a fix place (also in the RAM area). Static storage area holds the data that is available all the time when the program is running once it is created. You can specify a field of a object as a static variable with static.
2. Object
The following figure shows the layout of an object on the heap. The parts of the object are explained below the figure.
size + flags
The size + flags slot is 4 bytes on 32 bit architecture and 8 bytes on 64 bit architecture. The main purpose of this slot is to contain the length of the object. As all objects start on an 8 byte boundary, and the size is pisible by 8, the bottom 3 bits are not used for the size; we use them for flags to indicate different states of the object. As the size of objects is limited, the top 2 bits can be used for flags. Note that the mptr, not this slot, is grained on an 8 byte boundary. The flags are as follows:
Bit 1 is the swapped bit that is only used during compaction. Bit 1 is also the
NotYetScanned bit that is only used during mark stack overflow. In addition, Bit 1 is also the multi-pinned bit used to indicate that this object has been pinned multiple times.
During a GC, the multi-pinned bit will be removed and restored to allow other uses of this
Initialization & clean up java
overloaded bit.
Bit 2 is the dosed bit. The dosed bit is set on if the object is referenced from the stack or registers. The object cannot be moved in this GC cycle; we cannot fix up the reference as it may not be a real reference but simply an integer that happens to have the same value as an object on the heap.
Bit 3 is the pinned bit. Pinned objects usually cannot be moved because they are
referenced from outside the heap. Examples include Thread and ClassClass objects. Bit 31 in 32-bit architecture, or bit 63 in 64-bit architecture, is the flat locked contention (flc) bit used by the locking (LK) component.
Bit 32 in 32-bit architecture, or bit 64 in 64-bit architecture, is the hashed bit used to denote an object that has returned its hashed value. This is required, because the hash value is the address of the object and you need to maintain this if you move the object. mptr
The mptr slot is 4 bytes on 32-bit architecture and 8 bytes on 64-bit architecture. The mptr slot, not the size + flags, is grained on an 8 byte boundary. The mptr has one of two functions:
If the mptr slot is not an array, the mptr points to the method block, from which you can get to the class block. The class block tells you which class an object is an instantiation of. The class loader allocates the method block and class block, neither of which are in the heap.
If the mptr slot is an array, the mptr contains the number of array entries in this object. locknflags
This slot is 4 bytes on 32-bit architecture and 8 bytes on 64-bit architecture, although only …… 此处隐藏:15395字,全部文档内容请下载后查看。喜欢就下载吧 ……
相关推荐:
- [教学研究]2012西拉科学校团少队工作总结
- [教学研究]建筑工程公司档案管理制度
- [教学研究]小学数学人教版六年级上册圆的周长和面
- [教学研究]ERP电子行业解决方案
- [教学研究]钢支撑租赁合同范本
- [教学研究]预应力自动张拉系统用户手册Rev1.0
- [教学研究]MOOC课程:金瓶梅人物写真(每章节课后
- [教学研究]追加被执行人申请书(适用追加夫妻关系)
- [教学研究]2014年驾考科目一考试最新题库766
- [教学研究]2013-2014学年度九年级物理第15章《电
- [教学研究]新版中日交流标准日本语初级下26课-客
- [教学研究]小导管注浆施工作业指导书
- [教学研究]一般财务人员能力及人岗匹配评估表
- [教学研究]打1.2.页 小学一年级暑假口算100以内加
- [教学研究]学习贯彻《中国共产党党和国家机关基层
- [教学研究]2012年呼和浩特市中考试卷_35412
- [教学研究]最简易的电线电缆购销合同范本
- [教学研究]如何开展安全标准化建设
- [教学研究]工作分析与人岗匹配
- [教学研究]2016-2017学年高中历史第七单元现代中
- 山东省义务教育必修地方课程小学三年级
- 台湾宜兰大学互联网交换技术课程 01_In
- 思想品德:第一课《我知我家》课件(人
- SAR合成孔径雷达图像点目标仿真报告(附
- 利辛县“十三五”规划研究报告
- 2015-2020年中国手机APP行业市场发展趋
- 广告策略、创意表现、媒体方案
- 企业如何申请专利的的几点思考
- 《中国教育简史》网上作业
- 高中历史第二单元西方人文精神的起源及
- 年终晚会必备_精彩的主持稿_精心整理_
- 信息工程专业自荐书
- 2019高考历史人教版一轮练习:第十二单
- JAVA俱乐部管理系统软件需求规格说明书
- 2016-2021年中国小型板料折弯机行业市
- (人教新课标)六上_比的基本性质课件PPT
- 辽宁省公务员考试网申论备考技巧:名言
- 神经阻滞麻醉知情同意书
- 施工企业信息填报、审核和发布的相关事
- 初一(七年级)英语完形填空100篇




