HVM TP : A Time Predictable and Portable Java Virtual Machine for - - PowerPoint PPT Presentation

hvm tp a time predictable and portable java virtual
SMART_READER_LITE
LIVE PREVIEW

HVM TP : A Time Predictable and Portable Java Virtual Machine for - - PowerPoint PPT Presentation

HVM TP : A Time Predictable and Portable Java Virtual Machine for Hard Real-Time Embedded Systems JTRES 2014 Kasper Se Luckow 1 Bent Thomsen 1 Stephan Erbs Korsholm 2 1 Department of Computer Science 2 VIA University College Aalborg University


slide-1
SLIDE 1

HVMTP: A Time Predictable and Portable Java Virtual Machine for Hard Real-Time Embedded Systems JTRES 2014 Kasper Søe Luckow1 Bent Thomsen1 Stephan Erbs Korsholm2

1Department of Computer Science

Aalborg University Denmark

2VIA University College

Horsens Denmark

slide-2
SLIDE 2

17 2

Introduction HVMTP

Design

Tools

TETASARTSJVM TETASARTSTS Results

Conclusion

Future Work

Motivation

◮ WCET analysis necessitates that the temporal behavior of

the execution environment can be analysed

◮ Java Optimized Processor1

◮ Hardware Java Virtual Machine ◮ Execution times of the Java Bytecodes can be predicted

◮ This work addresses:

◮ Software Java Virtual Machine ◮ (Commodity) embedded hardware

1http://www.jopdesign.com/

slide-3
SLIDE 3

17 3

Introduction HVMTP

Design

Tools

TETASARTSJVM TETASARTSTS Results

Conclusion

Future Work

Contributions

◮ Time-predictable, software Java Virtual Machine

◮ Temporal behavior of Java Bytecodes can be modeled and

analysed

◮ HVMTP

◮ Accompanying tool support

◮ TETASARTSJVM ◮ TETASARTSTS

slide-4
SLIDE 4

17

Introduction

4

HVMTP

Design

Tools

TETASARTSJVM TETASARTSTS Results

Conclusion

Future Work

HVMTP at a Glance

SCJ Application HVM-SCJ Icecap SDK HVM VM Interface HW

Memory CPU Clock

HW Interface

... Interrupts I/O

◮ Based on the Hardware near Virtual Machine (HVM)2 ◮ Java-to-C compiler

◮ ICECAP-TOOLS ◮ Supports (iterative) interpretation ◮ Ahead-Of-Time compilation ◮ Tailors and optimises HVM for the hosted program

◮ Requirements: 256 kB flash and 20 kB RAM ◮ Self-contained (runs on bare metal), ANSI C

◮ ARM, AVR, x86, cr16c, . . .

2http://icelab.dk/

slide-5
SLIDE 5

17

Introduction HVMTP

5 Design

Tools

TETASARTSJVM TETASARTSTS Results

Conclusion

Future Work

Time-Predictability of HVMTP

◮ Time-predictability is possible by

◮ Harnessing the SCJ programming model ◮ HVMTP implements SCJ Level 1 ◮ Harnessing information obtained statically (ICECAP-TOOLS)

◮ This work focuses on the iterative interpreter (constant

time stages)

◮ Many Java Bytecodes from HVM are time-predictable ◮ Re-design comprises

◮ Object allocation ◮ Exceptions ◮ Method invocation ◮ Type checking of reference types ◮ . . . and a few others

slide-6
SLIDE 6

17

Introduction HVMTP

6 Design

Tools

TETASARTSJVM TETASARTSTS Results

Conclusion

Future Work

Object Allocation

◮ HVM performs zeroing at allocation time

◮ Linear time operation

◮ In HVMTP the heap structure is zeroed at Safelet

initialisation

◮ Zeroing happens when scoped memory is exited ◮ Performed in Java space using native variables

◮ Variables in the HVM accessible in Java space

slide-7
SLIDE 7

17

Introduction HVMTP

7 Design

Tools

TETASARTSJVM TETASARTSTS Results

Conclusion

Future Work

Exceptions

◮ SCJ permits exception objects to be pre-allocated before

entering a time critical phase

◮ ICECAP-TOOLS approximates the set of exceptions that

can be thrown

◮ E.g. athrow and idiv

◮ Exception handler is located in the call stack (linear time) ◮ Maximum call stack depth is estimated by ICECAP-TOOLS

◮ Reconstructs call graph ◮ Recursion is not allowed

slide-8
SLIDE 8

17

Introduction HVMTP

8 Design

Tools

TETASARTSJVM TETASARTSTS Results

Conclusion

Future Work

Method Invocation

1 case INVOKEVIRTUAL_OPCODE : { 2 const MethodInfo * mInfo ; 3 signed short excep ; 4 mInfo = findMethodInfo(&sp [ top ] , & method_code [ pc ] ) ; 5 excep = methodInterpreter(mInfo, &sp[top]); 6 / / . . . 7 }

Listing 1 : Original invokevirtual.

1 case INVOKEVIRTUAL_OPCODE : { 2 / / . . . 3 unsigned short pc = method_code − ( unsigned char * ) pgm_read_pointer(&method−>code , unsigned char * * ) ; 4 fp = pushStackFrame(mInfo, method, pc, fp, sp); 5 method = mInfo ; 6 / / . . . 7 }

Listing 2 : Using stack frames. ◮ The HVM employed recursion

◮ Difficult to analyse and model

◮ HVMTP implements a call stack ◮ HVMTP attempts to devirtualise call sites (using VTA) ◮ Method dispatch at virtual call sites (invokevirtual and

invokeinterface)

◮ Treated (almost) equally for simplicity ◮ Consult method tables of objectref’s class and superclasses ◮ Bounded by maximum height of class hierarchy ◮ (Obvious) future work: generate dispatch table

(invokevirtual)

slide-9
SLIDE 9

17

Introduction HVMTP

9 Design

Tools

TETASARTSJVM TETASARTSTS Results

Conclusion

Future Work

Type Checking Reference Types

◮ The HVM iteratively consults objectref’s class and

superclasses

◮ HVMTP exploits availability of the class hierarchy at

HVMTP construction time

◮ A bit matrix is constructed with entries denoting the type

compatibility of (x,y)

slide-10
SLIDE 10

17

Introduction HVMTP

Design 10

Tools

TETASARTSJVM TETASARTSTS Results

Conclusion

Future Work

Tool Support

◮ Tools for HVMTP:

◮ TETASARTSJVM ◮ TETASARTSTS

slide-11
SLIDE 11

17

Introduction HVMTP

Design

Tools

11 TETASARTSJVM TETASARTSTS Results

Conclusion

Future Work

TETASARTSJVM

1 case I2L_OPCODE : { 2 # i f defined (INSTRUMENT) 3 BEGIN_JBC ( I2L_OP ) ; 4 #endif 5 int32 lsb = *(−−sp ) ; 6 i f ( lsb < 0) { 7 * sp++ = −1; 8 } else { 9 * sp++ = 0x0 ; 10 } 11 * sp++ = lsb ; 12 method_code ++; 13 # i f defined (INSTRUMENT) 14 END_JBC ( I2L_OP ) ; 15 #endif 16 }

Listing 3 : i2l.

fetch! fetch! fetch! fetch! fetch! fetch! fetch! fetch! sbci_38 subi_37 movw_91 subi_92 ldd_33 movw_36 and_34 brge_35 asm_inst = asm_ldd asm_inst = asm_brge asm_inst = asm_subi asm_inst = asm_movw asm_inst = asm_subi asm_inst = asm_and asm_inst = asm_movw asm_inst = asm_brge sbci_93

Figure : Excerpt of TA for i2l. ◮ Generates a JVM Timing Model ◮ Timed Automata (TA) (UPPAAL3 model checker) ◮ Executable is instrumented ◮ Loop bounds provided comment-style

◮ All bounds are provided by ICECAP-TOOLS

◮ Reconstructs Control-Flow Graph and translates to TA

3http://www.uppaal.org

slide-12
SLIDE 12

17

Introduction HVMTP

Design

Tools

12 TETASARTSJVM TETASARTSTS Results

Conclusion

Future Work

TETASARTSJVM Cont’d

Figure : Fetch and execute TA from METAMOC4. ◮ Composition with HW TA yields the JVM Timing Model ◮ Verification of properties (TCTL)

◮ E.g. estimate execution times of the Java Bytecodes

4http://metamoc.dk/

slide-13
SLIDE 13

17

Introduction HVMTP

Design

Tools

TETASARTSJVM 13 TETASARTSTS Results

Conclusion

Future Work

TETASARTSTS

◮ TETASARTSTS generates a timing scheme from the JVM

Timing Model

◮ A timing scheme captures an abstract timing model of the

execution environment

◮ [BCETi,WCETi] for instruction i

slide-14
SLIDE 14

17

Introduction HVMTP

Design

Tools

TETASARTSJVM 14 TETASARTSTS Results

Conclusion

Future Work

The Big Picture

TetaSARTSJVM JVM Src

JVM Executable (AVR/ ARM/...) JVM Timing Model (Network of Timed Automata)

TetaSARTSanalyser TetaSARTSTS

JVM Timing Model (BCET and WCET)

Schedulability WCRT WCET Blocking Time ...

Analysis Result

SCJ Application

slide-15
SLIDE 15

17

Introduction HVMTP

Design

Tools

TETASARTSJVM TETASARTSTS 15 Results

Conclusion

Future Work

Results

◮ Constructing complete JVM Timing Model: 16s ◮ Generating a timing scheme for all Java Bytecodes:

◮ ∼ 4.5hours (without exception handling) ◮ ∼ 5days (with exception handling)

◮ Application-dependent Java Bytecodes:

◮ Only these must be re-analysed if the program is modified ◮ 13 (without exception handling) ◮ 47 (with exception handling)

◮ In reality, only a subset of the Java Bytecodes are used

◮ The Minepump uses 49 distinct Bytecodes → 5s (JVM

Timing Model) and 6m (timing scheme)

◮ Only two Java Bytecodes are application-dependent

(invokevirtual and invokeinterface)

slide-16
SLIDE 16

17

Introduction HVMTP

Design

Tools

TETASARTSJVM TETASARTSTS 16 Results

Conclusion

Future Work

Results Cont’d

Bytecode TETASARTSTS Measured BCET WCET Avg Low High i2l 129 136 130 130 130 aload_* 79 79 79 79 79 new 469 1715 1568 1568 1568 ireturn 505 1080 893 865 976 invokespecial 501 977 710 639 772 iinc 191 194 192 192 192 Times are represented in clock cycles. ◮ Simulation on Atmel AVR ◮ Measurements obtained from Atmel Studio 6 ◮ Safety: BCET ≤ Low and High ≤ WCET

slide-17
SLIDE 17

17

Introduction HVMTP

Design

Tools

TETASARTSJVM TETASARTSTS Results

Conclusion

17 Future Work

Future Work

◮ Further improve HVMTP

◮ E.g. invokevirtual

◮ Improve precision of JVM Timing Model

◮ CFG contains both feasible and infeasible execution paths ◮ Symbolic execution

◮ Evaluate analysis approach on other (and more complex)

hardware models