Memory Architecture
Memory Architecture
KIRAN KUMAR V
LENIN THUMMALAPALLI
C++ Memory Architecture
Specification
HEAP
STACK
STATIC Area
CODE
JVM Architecture
Specification
Method Area
Type Field
constant pool
information information
Method Table
Reference to
Method Class class loader
information and class
variables Class
Method Area
Fully qualified type’s
name.
Type Field Fully qualified direct
Constant
Information Informa super
pool
tion
class name.
Whether class or an
Method Ref. to interface
Class class loader Method
Informa- Table type's modifiers
variables and class
tion
Class list of the fully
qualified
names of any direct
super
interfaces
Method Area
Type Field Ordered set of
Informa Constant Pool Informa constants
tion tion - string
- integer
- floating point
- final variables
Method Ref. to
Class class loader Method symbolic references to
Informa- Table
variables and class - types
tion
Class
- fields
- Methods
Method Area
field’s name
Type field’s type
Constant Field
Informa field’s modifiers
pool Information
tion (subset )
- public
- private
Ref. to - protected
Method Method - static
Class class loader
Informa- Table - final
variables and class
tion - volatile
Class
- transient
Method Area
Method’s name
Type Method’s return type
Constant Field Number and type of
Informa Informa
pool parameters
tion tion Modifiers (subset)
Method
- public
Table
- private
Method Class - protected
Ref. to
Information variables - static
class loader
- final
and class
- synchronized
Class
- native
- abstract
Method Area
Type Field
Constant
Informa Informa
pool
tion tion ordered set of class
Method variables
Table
- static variables
Method
Class Ref. to
Informa
variables class loader
tion
and class
Class
Method Area
Type Reference to class
Constant Field
Informa Informa loader is used for
pool dynamic linking.
tion tion
instance
Method
Table java.lang.Class is
created every type for
Method Ref. to the following info.
Class
Informa Class loader - getName();
variables
tion And class - getSuperClass();
Class - isInterface();
- getInterfaces();
- getClassLoader();
Method Area
Type Field Used for quick ref. to
Constant
Informa Informa
pool
tion tion method.
System.out.println(result);
}
public static double
addTwoTypes(int i, double
d) {
return i + d;
}
}
class abc {
public int a;
String str;
Example
abc() {
a=10; atr=“string1”;
}
public void print{ System.out.print(a+” “+str); }
}
interface def {
void add();
}
class pqr extends abc implements def {
static int b;
final int c=50;
String s;
pqr(int m) { super(); b=m; s= new String(”string2”); }
void add() { a=a+c; add1(); }
static void add1() { c=b+50; }
}
class Main {
public static void main(String[] s) {
pqr p=new pqr(20);
p.add();
p.print();
}
}
class abc { Type Constant pool
public int a;
String str;
info
abc Symbol ref.
array
a st <init print
abc() { java.lang.Objec
t r >
a=10; 10
str=“string1”; Isclass=true “string1”
} modifier=4
Field
public void print{
System.out.print(a+”
info
name Type Modifier inde
“+str); a int 5 x 0
} str String 4 1
} Method
info
name ret.typ npa modifierparlist codept Method Class variable
<init> e void r 0 1 r Table
name index
print void 0 5 <init> 2 null
print 3
Class Area of abc in Method
area Symbolic ref. array
abc
java.lang.Objec
t
name Type Modifier index
Isclass=true
a int 5 0
modifier=4
ptr. to interface list str int 4 1
ptr. to symbolic ref. array
ptr to field info
name ret.typ npa modifierparlistcodeptr
ptr to method info
<init> e void r 0 5
ptr to class variable list print void 0 5
Method
Table
name
index
add 0
Class Area of def in Method
area
def
java.lang.Objec
t
Isclass=false
Symbolic ref. array
modifier=4
ptr. to interface list
ptr. to symbolic ref. array
ptr to field info
name ret.typ npa modifierparlistcodeptr
ptr to method info
add e void r 0 4
ptr to class variable list
50 > 1 S String 4 2
Method Method
info npa
name ret.typ modifierparlistcodept Table
name
<init> e void r 1 4 r
index
<init> 3
add void 0 4 add 5
add1 void 0 4 add 6
super void 0 4 1
super 4
Class Area of pqr in Method
area Symbolic ref. array
pqr
abc
Isclass=true name Type Modifier index
Method
Table
name
index
main 0
Class Area of Main in Method
area
Main
java.lang.Objec
t
Isclass=true
Symbolic ref. array
modifier=4
ptr. to interface list
ptr. to symbolic ref. array
ptr to field info
name ret.typ npa modifierparlistcodeptr
ptr to method info
main e void r 0 5,6
ptr to class variable list
p str
stack main p main s
Heap a,b,c
string2
Main pqr
Main pqr Main pqr
p
p p
main
Pqr.<init
>
Pqr.<init
> abc.<init
>
Main pqr abc Main pqr abc
Main pqr abc
p str p str
s s str
s
prin
a,b,c
t
string2
a,b,c string2
Relation between C++
memory structure and JVM
memory structure
Constant STATIC Area
pool
CODE
Field Class
Informa variables
tion
Type
Informa
Metho
Metho
tion Metadata dd
Area
Area
Method Ref. to
Method
Informa class loader
Table
tion and class
Class
Garbage collection
JVM Heap
C++ Heap
Frame data
Operand
Stack Threaded
Threaded
JVM
JVM
Stack
Stack
JVM stack
Threads
C++ stack
Responsibilities of Memory
Mgr
Chop the chunk.
Allocate Requested number of bytes.
Provide necessary information to
garbage
collector.
Collect the bytes returned by garbage
collector.
Defragment the chunks.
Design Choices
How to allocate bytes
- Contiguous memory allocation.
- Non contiguous memory allocation.
How many bytes to be allocated
- exact requested number of bytes.
- Allocate bytes in terms of 2^n (Buddy
System).
How defragmentation to be done
- Compaction.
- Buddy system.
JVM Memory Manager
Algorithms Followed
Noncontiguous Memory Allocation.
First fit to choose approperiate chunk.
Buddy system to chop a chunk.
Buddy system for defragmentation.
How to implement memory
manager
Need of 4 threads
- Memory allocator.
- Memory Defragmenter.
- Chunk cleaner.
- Data manager.
When VM requests m bytes
Allocator
1. Checks for first chunk with size
>=m+4.
2. If available chops it and returns to VM
else requests OS for new chunk.
Data Manager inserts an entry in Memory
Allocation Table (for garbage collector ).
Java JVM
M/C 2
M/C 1
C#
CLR
VB M/C 2
ClR MM
- Allocation is simple.
- Defragmentation is complex.
JVM Memory Manager
Algorithms Followed
Contiguous Memory Allocation.
Compaction for defragmentation.
Lazy Defragmenter
Memory Managers
Type Memory manager. GC runs.
Roots Memory No GC.
manager. GC runs.
Managed heap No GC.
manager.
Unmanaged
To deallocate heap
Unmanaged Memory
Finalizers should be used.
manager.
Before GC After GC
Memory
Allocation
Next Ptr
Obj 3
Obj 2
Obj 1
Thank You