enhancing the region model of rtsj

25
Enhancing the region model of real- time Java for large-scale systems Pablo Basanta-Val Marisol García-Valls Iria Estévez-Ayres Universidad Carlos III de Madrid Telematics Engineering Department

Upload: universidad-carlos-iii-de-madrid

Post on 20-Nov-2014

423 views

Category:

Documents


1 download

DESCRIPTION

AGCMemory

TRANSCRIPT

Page 1: Enhancing the region model of RTSJ

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

Page 2: Enhancing the region model of RTSJ

2/25

Outline

Introduction

Recycling Floating Garbage with AGCMemory

Extending RTSJ Hierarchy

Supporting AGCMemory

Conclusions and future work

Page 3: Enhancing the region model of RTSJ

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

Page 4: Enhancing the region model of RTSJ

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

Page 5: Enhancing the region model of RTSJ

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

Page 6: Enhancing the region model of RTSJ

Recycling Floating Garbage with AGCMemory

Floating garbageUsing nested scopes to eliminate floating garbageUsing AGCMemory to eliminate floating garbage

Page 7: Enhancing the region model of RTSJ

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. }

Page 8: Enhancing the region model of RTSJ

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

Page 9: Enhancing the region model of RTSJ

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. }

Page 10: Enhancing the region model of RTSJ

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

Page 11: Enhancing the region model of RTSJ

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

Page 12: Enhancing the region model of RTSJ

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. }

Page 13: Enhancing the region model of RTSJ

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

Page 14: Enhancing the region model of RTSJ

Extending RTSJ Hierarchy

Page 15: Enhancing the region model of RTSJ

15/25

AGCMemory in the RTSJ class Hierarchy

HeapMemory

Memory Area

VTMemory LTMemory AGCMemory

Scoped Memory

ImmortalMemory

ImmortalPhysicalMemory

LTPhysicalMemory VTPhysicalMemory

Page 16: Enhancing the region model of RTSJ

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

Page 17: Enhancing the region model of RTSJ

Supporting AGCMemory

StructuresRuntime barriersExample revisited

Page 18: Enhancing the region model of RTSJ

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

Page 19: Enhancing the region model of RTSJ

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

Page 20: Enhancing the region model of RTSJ

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

Page 21: Enhancing the region model of RTSJ

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

Page 22: Enhancing the region model of RTSJ

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()

Page 23: Enhancing the region model of RTSJ

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

Page 24: Enhancing the region model of RTSJ

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

Page 25: Enhancing the region model of RTSJ

25/25

Enhancing the region model of real-time Java for large-scale systems

Thanks