Memory Management - PowerPoint PPT Presentation

1 / 35
About This Presentation
Title:

Memory Management

Description:

Java heap and immortal objects cannot reference scoped object. ... Objects in immortal memory live for the lifetime of the application. ... – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 36
Provided by: mikkola
Category:

less

Transcript and Presenter's Notes

Title: Memory Management


1
Memory Management
  • Real-Time Java Specification
  • Mikko Laukkanen

2
Presentation outline
  • Background
  • Javas current memory management.
  • Garbage collection techniques.
  • RTJSs concepts on memory management.
  • RTJS-specified classes for memory management.
  • Conclusion.

3
Java Memory Management
  • Class area
  • Code and constants.
  • Java stack
  • Keeps track of method execution and data
    associated with each method invocation.
  • Heap
  • Place where objects live.
  • Native method stacks.
  • For supporting native methods.

4
Class area
Class name
Superclass name
Fields
Method definitions
Code area
5
Java stack
6
Heap
7
Native stacks
  • Native methods usually use stack to keep track of
    their state.
  • JVM provides a native stack that native methods
    can use.
  • Most commonly supported standard for native
    methods is Java Native Interface (JNI).

8
Garbage collection - rules
  • If there is a reference to the object on the
    stack, then it is alive.
  • If there is a reference to the object in a local
    variable, on the stack, or in a static field,
    then it is alive.
  • If a field of a live object contains a reference
    to some object, this object is also alive.
  • The JVM may internally keep references to a
    certain objects, for example, to support native
    methods. These objects are alive.

9
Garbage collection - techniques
  • Basic techniques
  • Reference counting
  • Mark-and-sweep
  • Mark-and-compact
  • Copying collector
  • Incremental tracing collectors
  • Tri-colour marking
  • Generational techniques
  • Young generations of objects are more probably
    garbage.

10
Real-time garbage collectors?
  • Reference counting
  • References need memory.
  • Cannot handle circular references.
  • Reduces efficiency.
  • Incremental collectors
  • Fine-grained incremental collector is a good
    candidate for RT garbage collector.

11
Presentation outline
  • Background
  • Javas current memory management.
  • Garbage collection techniques.
  • RTJSs concepts on memory management.
  • RTJS-specified classes for memory management.
  • Conclusion.

12
RTJS principles
  • Garbage-collected heaps wont work!
  • Work-around lets have memory areas that are
    never garbage collected.
  • Both short-lived and long-lived objects can be
    allocated from these memory areas.

13
Memory areas
  • Scoped memory
  • Lifetime defined by syntactic scope.
  • Physical memory
  • Access to physical memory addresses directly.
  • Immortal memory
  • Objects alive as long as the application.
  • Heap memory
  • Standard Java heap.

14
Requirements for memory areas
  • Linear allocation time in some areas.
  • Scoped areas
  • Own reference counters for scopes.
  • Scopes may be nested.
  • Immortal areas
  • JVM has exactly one immortal area.
  • Immortal objects live for the duration of the
    application.
  • Heap memory area
  • JVM has exactly one heap memory area.

15
Assignment restrictions
  • JVM must ensure that above checks are performed
    before the statement is executed!

16
RTJS garbage collector requirements
  • GC algorithm is independent and can be changed,
  • Programmer is able to precisely characterise an
    implemented GC algorithm's effect on the
    execution time, preemption, and dispatching of
    real-time Java threads, and
  • Allocation and reclamation of objects is possible
    outside of any interference by any garbage
    collector algorithm.

17
Presentation outline
  • Background
  • Javas current memory management.
  • Garbage collection techniques.
  • RTJSs concepts on memory management.
  • RTJS-specified classes for memory management.
  • Conclusion.

18
MemoryArea class - overview
  • Abstract base class.
  • enter () method for entering to the area.
  • Methods for object creation
  • newInstance ()
  • newArray ()
  • Query methods for consumed and remaining memory
    as well as the size of the memory area.

19
MemoryArea class - diagram
20
Heap memory - overview
  • Allows access to standard Java heap.
  • Singleton class.

21
Heap memory - diagram
22
ScopedMemory - overview
  • Abstract base class.
  • Represents memory space with a limited lifetime.
  • ScopedMemory class itself is instantiated in the
    currently used memory area.
  • Pointer safety rules
  • Java heap and immortal objects cannot reference
    scoped object.
  • A reference to a scoped object cannot be assigned
    into the enclosing scope.

23
ScopedMemory - diagram
24
ScopedMemory - example
  • Example 1
  • Example 2

final ScopedMemory s new LTMemory
(16,1024) s.enter (new Runnable () public void
run () try s.newInstance
(Class.forName ("Foo")) catch
(Exception e) )
final ScopedMemory s new LTMemory
(16,1024) RealtimeThread t new RealtimeThread
(null, null,
new MemoryParameter
(s), null,
new Runnable ()

public void run ()

// ...

25
ImmortalMemory - overview
  • Shared among all threads.
  • Objects in immortal memory live for the lifetime
    of the application.
  • Is not garbage collected, but may be scanned.
  • Singleton class.

26
ImmortalMemory - diagram
27
RawMemoryAccess - overview
  • A storage for a fixed-size sequence of bytes.
  • Allows different type of memories.
  • Allows implementation of device drivers, memory
    mapped I/O and similar kind of low-level
    software.
  • Is created by the PhysicalMemoryFactory.

28
RawMemoryAccess - diagram
29
Physical memory areas - overview
  • Allows creation of object mapped to a physical
    memory addresses.
  • Rationale is that for instance faster RAM could
    be used, if needed.
  • Two kinds of classes
  • ImmortalPhysicalMemory
  • ScopedPhysicalMemory
  • Both are created by PhysicalMemoryFactory.

30
Physical memory areas - diagram
31
Creating the physical memory areas
32
Garbage collectors - overview
  • System shall provide dynamic and static
    information about GC overhead.
  • GC structure is really simple, only guidelines
    are specified and examples given.
  • Only one mandatory method getPreemptionLatency
    ().
  • Example garbage collectors are just examples and
    are not required for RTJS-compliant
    implementation.

33
Garbage collector - diagram
34
Presentation outline
  • Background
  • Javas current memory management.
  • Garbage collection techniques.
  • RTJSs concepts on memory management.
  • RTJS-specified classes for memory management.
  • Conclusion.

35
Conclusion
  • Automatic memory management and especially
    garbage collection is an obstacle for real-time
    applications.
  • RTJS works around this by defining memory areas
    that are not garbage collected.
  • However, (real-time) garbage collecting
    algorithms can be used.
Write a Comment
User Comments (0)
About PowerShow.com