Memory space manipulating in Java(Section one:Basic Concepts in Java)

原创 2007年09月23日 14:09:00

HTML Tags and JavaScript tutorial

Memory space manipulating in Java(Section one:Basic Concepts in Java)

After reading several articles on memory handling in Java in AIX, I decided to write something about this topic. For purposes of doing a summary for myself, also I hope it could be helpful to those who want to know it.
Basic Concepts in Java
  Before enter our main topic, we are going to review some basic concepts in Java.
Those who have been familiar with following concepts can skip this section.
In world of Java, we know that everything is an
(except for primitive type like int, double and so on).
In Java there is not a word named pointer, which should be very familiar to people who have been experienced of C/C++, to manipulate an object,
there is a new word
have been introduced, which also can be seen as an object, is used to help to manipulate the target object. It looks somewhat like a wrapper object of C/C++ pointer, as you can still remember you use *somePointerName to manipulate value of the target address in .
Besides Reference, you know there must be something that used to define what the type of object is. The keyword
, which is used to express the structure of the given Object, have used in most object-oriented languages. A
is usually consists of two members: data elements & functionality, which also know as Fields & Methods.
A data member could be primitive data type, or a reference to a specified object. And functionality, also call method, means a way to do something.
Storage lives in Java
When you create an object with its reference, where they are being kept? Again, there may come to several terminologies.
: Fastest storage because it exists directly inside the processor. They can be allocated by compiler, which instead, may have been created by using
Assembling or C language.
: Creating objects on the stack is the most efficient way to allocate storage for objects and to free that storage. But with constraint of limited space and explicitly specifying size & lifecycle of the object. In Java, usually references to the Objects will be kept here. And those with primitive data type, also will be kept here, thus access to primitive data type normally can get a higher speed.
(To give size for a random object instance is impossible, but as to primitive type, Java determines the size of each primitive type and it would change from
one machine to another.)
: In a sense you can treat JVM as a normal process running in an Operating System. There should be an area of memory allocated for the process used for dynamic memory allocation. When you create an object with
statement, you are asking JVM for allocating a space in Heap to place the object.
We will see it in more detail in the following section.
Static storage
: “Static” is used here in the sense of “in a fixed location” (although it’s also in RAM). Static storage contains data that is available for the entire time a program is running.
Notice that here what does the word program mean? Each JVM will have its own static area which used as storage for static data. That mean your WebSphere Application Servers can’t run into each other’s static area as they run on different JVM, the same to your Java class start by running main(). (This becomes possible since JDK 5.0)
You can use the static keyword to specify that a particular element of an object is static, but Java objects themselves are never placed in static storage.
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.
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 a regular RAM-based object when necessary. Java provides support for lightweight persistence, and future versions of Java might provide more complete solutions for persistence.
Run your Java code
  We know Java is one of intercept programming languages, which means it can not be executed directly until being translated into instruction code by correspondent interceptor. The following steps simply show what need to be done to make your Java code executable.
to compile your java source into bytecodes. This will result in .class file which contains data & functionality elements of the java source, being created.
to execute your java bytecodes. This action in fact, will firstly compile the bytecodes into native machine code (instruction code) that can be recognized & execute by hardware. In normal case, the final compiled instruction code will consist of data & text; this should be the same as C/C++, even Assembling Language.
         Note that JIT plays an important role here. I will simply explain it with the following 
The JIT Compiler comes into use when a Java method is called; it compiles the bytecodes of
that method into native machine code, compiling it

just in time

to execute. When a method has been compiled 
(The JVM interprets a method until its call count exceeds a JIT threshold)
, the JVM calls the compiled code of that method directly instead of interpreting it.
If you want to know more about Java, I would suggeset you to read Thinking In Java Third Edition, as in this section I have referred many from there.

Java heap space 解决方法(转)

因为程序要从数据读取近10W行记录处理,当读到9W的时候就出现 java.lang.OutOfMemoryError: Java heap space 这样的错误。 在网上一查可能是JAVA的堆栈设...
  • yuan1013922969
  • yuan1013922969
  • 2016年08月30日 11:33
  • 8584

解决spark运行时Java heap space问题

问题描述: 在执行spark程序时,需要读取200w数据作为缓存,遇到Exception in thread "main" java.lang.OutOfMemoryError: Java heap ...
  • xiaoxinwenziyao
  • xiaoxinwenziyao
  • 2015年09月15日 14:43
  • 5700

一段死循环引发的Java heap space类型的OutOfMemory

一段死循环引发的Java heap space类型的OutOfMemory
  • Knight_hf
  • Knight_hf
  • 2016年08月01日 15:32
  • 1333

java heap space解决方法和JVM参数设置

在JVM中如果98%的时间是用于GC(Garbage Collection)且可用的 Heap size 不足2%的时候将抛出异常信息,java.lang.OutOfMemoryError: Java...
  • chenlei0630
  • chenlei0630
  • 2013年12月06日 01:47
  • 10083


 一、IAR中的重复定义问题      在自己写头文件时,要记得将常量定义在.c文件中,如果将常量定义在.h文件中,当在main.c或者其他地方包含该头文件时,会将头文件中的常量定义包含到ma...
  • qq_18707505
  • qq_18707505
  • 2016年04月07日 15:32
  • 453

我碰到的Java heap space问题

java heap space 今天帮别人调bug,是一个读取文件的程序,之前文件不大的时候没出过这个错误,文件大了就出了 开始我以为是jvm内存配置问题,但是配置到最大依然无效(就那个在jdk那...
  • nfsnyy007
  • nfsnyy007
  • 2015年12月01日 10:20
  • 8232

使用Memory Analyzer tool(MAT)分析内存泄漏(二)

前言 在使用Memory Analyzer tool(MAT)分析内存泄漏(一)中,我介绍了内存泄漏的前因后果。在本文中,将介绍MAT如何根据heap dump分析泄漏根源。由于测试范例可能过于简...
  • u012264122
  • u012264122
  • 2016年07月27日 15:47
  • 770

计算机科学基础知识(一):The Memory Hierarchy 一、前言 最近一个问题经常萦绕在我的脑海:一个学习电子工程的机械...
  • linux58
  • linux58
  • 2017年08月09日 15:52
  • 124


原文地址: 摘要 在工作中可能会遇到内存溢出这种灾难性的问题,那么程序肯定是存在问题,找出问题至...
  • wanglha
  • wanglha
  • 2015年06月26日 10:25
  • 383

hadoop的mapreduce作业中经常出现Java heap space解决方案

我们经常遇到这样的问题,内存溢出,内存溢出的原因是很简单,不够用了,不够用该怎么设置,通过水设置。可以参考下面案例 一、hadoop的mapreduce作业中经常出现Java heap space解...
  • xiaoshunzi111
  • xiaoshunzi111
  • 2016年08月10日 16:30
  • 2875
您举报文章:Memory space manipulating in Java(Section one:Basic Concepts in Java)