enhancing the region model of rtsj
DESCRIPTION
AGCMemoryTRANSCRIPT
Enhancing the region model of real-time Java for large-scale systems
Pablo Basanta-ValMarisol García-VallsIria Estévez-Ayres
Universidad Carlos III de MadridTelematics Engineering Department
2/25
Outline
Introduction
Recycling Floating Garbage with AGCMemory
Extending RTSJ Hierarchy
Supporting AGCMemory
Conclusions and future work
3/25
Introduction (I)
Good properties of Java make it suitable for large-scale systems:
Portability
Automatic memory management (garbage collector)
Simplicity
Networking support…
When we introduce real-time constraints problems with automatic memory management
Garbage collector introduces unpredictable breaks in program execution deadlines may be missed
4/25
Introduction (II)
Possible solutions:Real-time garbage collector techniques
Regions (e.g in RTSJ Scope Memory)
Neither is perfectReal-time garbage collectors maintain the Java programming style but they are not easy to tune
Regions provide predictability but they modify the programming style
5/25
Introduction (and III)
Our approach is a new type of region for RTSJ: AGCMemory
It tries to improve the portability of regions while keeping some of the advantages of GC-techniques
It maintains the Java programming style
It provides the predictability of regions
It reduces the number of manual changesMore portable applications
It enhances the reuse of code and it decreases the development time
Recycling Floating Garbage with AGCMemory
Floating garbageUsing nested scopes to eliminate floating garbageUsing AGCMemory to eliminate floating garbage
7/25
Motivation: PeriodicCounter1. import javax.realtime.*2. public class PeriodicCounter extends RealtimeThread{3. public PeriodicConter(){4. super( null,//Schedulling par5. new PeriodicParameters(null,6. new RelativeTime(1000,0), //T7. new RelativeTime(50,0), //C8. new RelativeTime(100,0), //D9. null,null /*Handlers*/);10. null, //Memory parameters11. new LTMemory(100,100), //Mem. param12. null); 13. start(); //starts thread.14. } 15. int counter=1;16. public void run(){17. do{18. System.out.println(counter); // Allocates 88 bytes in RTSJ-RI19. counter++20. }while(waitForNextPeriod());21. }22. public static void main(String s[]){23. new HelloPeriodicCounter();24. }25. }
8/25
Motivation (II)
./RTSJ-RI PeriodicCounter123Mem-registry.c::InvokeNewInstance()- Went out of memory
250 free bytes 11. new LTMemory(300,300)
162 freebytes
18. System.out.println(counter)
74 freebytes
18. System.out .println(counter)
-8 free bytes
18. System.out .println(counter)
OutOfMemory Exception
9/25
Solving the problem with nested scopes
1. import javax.realtime.*2. public class PeriodicCounter extends RealtimeThread{3. public PeriodicCounter(){4. //UnChanged}5. 6. int counter=1;7. public void run(){8. LTMemory lt=new LTMemory(150,150); //Nested scope9. Runnable impr=new Runnable(){10. public void run(){11. System.out.println(counter);};12.13. do{ lt.enter(impr); counter++;14. }while(waitForNextPeriod());15. }16. public static void main(String s[]){17. new HelloPeriodicCounter();18. }19. }
10/25
220 byteslibres
Solving the problem with nested scopes (II)
250 bytes memoria libre new LTMemory(300,300)
220 bytes libres
9. lt=new LT(150,150)10. 10. Runnable impr
13. lt.enter(impr);
150 b. impr
150 b. impr
150 bytes libres
62 bytes libres
150 bytes libres
13. counter++;
//Using nested scope
//Executes impr.run
//Release nested scope
11/25
Nested Scopes Problems
The programmer has to set up:Number of auxiliary scopesMaximum size of each auxiliary scope
Other problems:Low portability
High dependency on available classes
Not especially intuitive (runnable objects)Runnable classes required
Our solution: AGCMemory
12/25
AGCMemory
1. import javax.realtime.*2. public class PeriodicCounter extends RealtimeThread{3. public PeriodicConter(){4. super( null,//Schedulling par5. new PeriodicParameters(null,6. new RelativeTime(1000,0), //T7. new RelativeTime(50,0), //C8. new RelativeTime(100,0), //D9. null,null /*Handlers*/);10. null, //Memory parameters11. new AGCMemory(250,250), //Mem. param12. null); 13. start(); //starts thread.14. } 15. int counter=1;16. public void run(){17. do{18. System.out.println(counter); counter++19. }while(waitForNextPeriod());20. }21. public static void main(String s[]){22. new HelloPeriodicCounter();23. }24. }
13/25
Using AGCMemory
250 free bytes 11. new AGCMemory(300,300)
162 free bytes
18. System.out.println(counter)
250 free bytes //preinvocation
//printing the counter
250 free bytes //memory releasing
18. counter++250 free bytes
Extending RTSJ Hierarchy
15/25
AGCMemory in the RTSJ class Hierarchy
HeapMemory
Memory Area
VTMemory LTMemory AGCMemory
Scoped Memory
ImmortalMemory
ImmortalPhysicalMemory
LTPhysicalMemory VTPhysicalMemory
16/25
LTMemory VTMemory AGCMemory comparison
LTMemory VTMemory AGCMemory
Allocation time Linear Not bounded Linear
De-allocation after enter method
Yes Yes Yes
Partial de-allocation Not supported
Yes
(when objects are allocated)
Yes
(after method invocation)
Predictable partial de-allocation
A priori, not bounded
Yes
Shared Yes Yes No
Supporting AGCMemory
StructuresRuntime barriersExample revisited
18/25
AGCMemory Internal Structures
agc_stack
toptop-1
0
.
.
.
top-2
method_ptr scape_ptr
0xAC00
0x0C00
free_mem_ptr
physical memory
Chunk of physical memory:Objects are allocated in ascending memory addressesfree_mem_ptr: position where the next object will be allocated
AGCstack (used in memory management algorithm)scape_ptr: decides whether the objects created during the invocation of a method maybe recycled or not.method_ptr: stores information about the set of objects created during the invocation of a method
19/25
Runtime Barriers
Barrier Pseudo-code Functionality
pre_invocation(before executing a
method)
Agc.stack.push(memPtr, memPtr)
topscape_ptr = free_mem_ptr;
topmethod_ptr = free_mem_ptr;
It identifies the objects that will be created in the invocation of a method
post_invocation(after executing a
method)
If(top→scape_ptr ≥ top→method_ptr )Free objects [top→method_ptr, free_prtr]
else (top_1→scape_ptr=top→scape_ptr)
Agc.stack.pop()
It destroys floating objects or propagates their destruction
Intra_asig.(before executing an
assigment)
Attrib=ref
if (memArea(attrib)==memArea(ref))
&& (memArea(attrib) instance of AGCMemory)
&& (refattrib)
topscape_ptr=min{topscape_ptr, attrib}
It detects whether the objects of a method may be destroyed when the methods ends
20/25
Example revisited (I)
Pre-invocation barrier (executed before System.out.println())Agc.stack.push(memPtr, memPtr)
topscape_ptr = free_mem_ptr;
topmethod_ptr = free_mem_ptr;
250 free bytes00
agc_stacktop
free_mem_ptr (0)
method_ptr
scape_ptr
21/25
Example revisited (II)
Object creation inside method System.out.println
162 free bytes00
agc_stacktop
free_mem_ptr (88)
method_ptr
scape_ptr
22/25
Example revisited (and III)
250 free bytes00
agc_stacktop
free_mem_ptr (0)
Post-invocation barrier (executed after System.out.println())If(top→scape_ptr ≥ top→method_ptr )Free objects [top→method_ptr, free_prtr]
Agc.stack.pop()
23/25
Conclusions
Existing types of regions hard to useFloating garbage problem
AGCMemory:It reduces floating garbage problem
It improves the automatic memory management
Easier to use than nested scopes
It uses constant time barriers
24/25
Future work
Implementation of AGCMemory in a RTSJ open source virtual machine
We are using JRate
Evaluation of the following trade-offs:Influence of the assignment AGCMemory barrier in the performance of applications
Analysis of required memory for different types of applications
25/25
Enhancing the region model of real-time Java for large-scale systems
Thanks