University of Southampton Research Repository Eprints Soton
Total Page:16
File Type:pdf, Size:1020Kb
University of Southampton Research Repository ePrints Soton Copyright © and Moral Rights for this thesis are retained by the author and/or other copyright owners. A copy can be downloaded for personal non-commercial research or study, without prior permission or charge. This thesis cannot be reproduced or quoted extensively from without first obtaining permission in writing from the copyright holder/s. The content must not be changed in any way or sold commercially in any format or medium without the formal permission of the copyright holders. When referring to this work, full bibliographic details including the author, title, awarding institution and date of the thesis must be given e.g. AUTHOR (year of submission) "Full thesis title", University of Southampton, name of the University School or Department, PhD Thesis, pagination http://eprints.soton.ac.uk UNIVERSITY OF SOUTHAMPTON FACULTY OF PHYSICAL AND APPLIED SCIENCES Electronics and Computer Science Run-time Compilation Techniques for Wireless Sensor Networks by Joshua Ellul Thesis for the degree of Doctor of Philosophy November 2012 UNIVERSITY OF SOUTHAMPTON ABSTRACT FACULTY OF PHYSICAL AND APPLIED SCIENCES Electronics and Computer Science Doctor of Philosophy RUN-TIME COMPILATION TECHNIQUES FOR WIRELESS SENSOR NETWORKS by Joshua Ellul Wireless sensor networks research in the past decade has seen substantial initiative, support and potential. The true adoption and deployment of such technology is highly dependent on the workforce available to implement such solutions. However, embedded systems programming for severely resource constrained devices, such as those used in typical wireless sensor networks (with tens of kilobytes of program space and around ten kilobytes of memory), is a daunting task which is usually left for experienced embedded developers. Recent initiative to support higher level programming abstractions for wireless sensor networks by utilizing a Java programming paradigm for resource constrained devices demonstrates the development benefits achieved. However, results have shown that an interpreter approach greatly suffers from execution overheads. Run-time compila- tion techniques are often used in traditional computing to make up for such execution overheads. However, the general consensus in the field is that run-time compilation tech- niques are either impractical, impossible, complex, or resource hungry for such resource limited devices. In this thesis, I propose techniques to enable run-time compilation for such severely resource constrained devices. More so, I show not only that run-time compilation is in fact both practical and possible by using simple techniques which do not require any more resources than that of interpreters, but also that run-time compilation substantially increases execution efficiency when compared to an interpreter. Contents Declaration of Authorship xvii Acknowledgements xix Nomenclature xxiii 1 Introduction 1 1.1 Enabling Java for Sensor Nodes ........................ 3 1.2 Challenges, Motivation and Requirements .................. 4 1.3 Overview of Work ............................... 5 1.4 Relationship to Existing Approaches ..................... 6 1.5 Research and Contributions .......................... 7 1.6 Outline of Thesis ................................ 9 2 Related Work 11 2.1 WSN Requirements and Issues ........................ 11 2.2 WSN Programming Paradigms ........................ 13 2.2.1 Node-Level Programming ....................... 13 2.2.1.1 OS / Bare-metal Programming ............... 13 2.2.1.2 Virtual Machines ....................... 15 2.2.2 Group-Level Programming ...................... 15 2.2.3 Network-Level Programming ..................... 16 2.3 Java ....................................... 18 2.3.1 The Class File Format ......................... 18 2.3.2 JVM Stacks, Method Frames and Operand Stacks ......... 19 2.3.3 Java Bytecode Instruction Specification ............... 20 2.3.3.1 Load and Store Instructions ................ 21 2.3.3.2 Arithmetic Instructions ................... 22 2.3.3.3 Type Conversion Instructions ................ 22 2.3.3.4 Object Creation and Manipulation ............. 23 2.3.3.5 Control Transfer Instructions ................ 24 2.3.3.6 Method Invocation and Return Instructions ........ 24 2.3.3.7 Exceptions .......................... 25 2.3.3.8 Synchronization Instructions ................ 25 2.3.3.9 Operand Stack Management Instructions ......... 25 2.4 Desirability of Java for WSNs ......................... 25 2.5 Sensor Nodes are for WSNs, not for Java Purists .............. 27 2.5.1 Need for a New Java Platform Specification ............. 27 v vi CONTENTS 2.5.1.1 Strings and Encodings .................... 28 2.5.1.2 The double Datatype .................... 28 2.5.1.3 IO, Streams and Connections ................ 28 2.5.1.4 Calendars and Dates ..................... 29 2.5.1.5 Dynamic Class Loading ................... 29 2.5.1.6 Exceptions and Threads ................... 30 2.5.2 Code Conventions ........................... 30 2.6 JVMs for WSNs ................................ 31 2.6.1 Application Portability ........................ 32 2.6.2 Pre-processing Bytecode ........................ 32 2.6.3 Compact Bytecode Instruction Set .................. 32 2.6.4 Bytecode Optimisation ......................... 33 2.6.5 Symbolic Name Resolution ...................... 34 2.6.6 Language Independence ........................ 35 2.6.7 Garbage Collection ........................... 35 2.6.7.1 Mark and Sweep GC .................... 36 2.6.7.2 Mark and Compact GC ................... 36 2.6.7.3 Generational GC ....................... 36 2.6.7.4 Offline GC .......................... 37 2.6.8 Threading ................................ 37 2.6.9 Debugging ................................ 38 2.7 Interpretation is slow .............................. 38 2.8 Java Processors ................................. 38 2.9 Compilation, Interpretation and Semi-Compilation ............. 39 2.10 Way Ahead of Time Compilation ....................... 40 2.11 Ahead-Of-Time Compilation ......................... 41 2.12 Just-In-Time Compilation ........................... 41 2.13 Basic Block JIT ................................. 42 3 The Case for Run-time Compilation of Bytecode in Wireless Sensor Networks 43 3.1 Modelling Interpretation Overheads ..................... 43 3.2 An Experimental Analysis of the Effects of Interpretation .................................. 48 4 Enabling AOT Compilation for Resource Constrained Devices 51 4.1 Design ...................................... 51 4.1.1 Requirements .............................. 51 4.1.1.1 Ease of Use .......................... 52 4.1.1.2 Platform Independence ................... 52 4.1.1.3 Memory Efficiency ...................... 52 4.1.1.4 Small Footprint ....................... 52 4.1.1.5 Driver Extensibility ..................... 52 4.1.1.6 Software Management .................... 53 4.1.1.7 Low-cost ........................... 53 4.1.1.8 Execution Efficiency ..................... 53 4.1.2 System Architecture .......................... 54 CONTENTS vii 4.1.3 Compilation Process .......................... 55 4.1.3.1 Java Source Pre-processor .................. 55 4.1.3.2 Converter ........................... 56 4.1.4 AOT Compiler and Execution ..................... 59 4.1.4.1 Double-Ended Operand Stack and Garbage Collection .. 60 4.1.4.2 Stack Frame Layout ..................... 62 4.1.4.3 Threading .......................... 65 4.1.4.4 Optimizations ........................ 66 4.1.4.5 Gradual Compilation of Bytecode ............. 68 4.1.5 Hardware Register Access ....................... 70 4.1.6 Exposing Interrupts .......................... 70 4.2 Implementation Specific Details ........................ 71 5 Evaluation of the AOT Compiler 75 5.1 Execution Performance Evaluation ...................... 76 5.2 Program Size Evaluation ............................ 79 5.2.1 Program Encoding Size Evaluation .................. 80 5.2.2 Virtual Machine and Application Size Evaluation .......... 81 5.3 Garbage Collection Evaluation ........................ 83 5.4 Threading Evaluation ............................. 84 5.5 Evaluation Discussion ............................. 85 6 Enabling JIT Compilation for Resource Constrained Devices 87 6.1 Basic Block JIT Compilation ......................... 88 6.1.1 Offline Basic Block Analysis ...................... 88 6.1.2 Supporting a JIT Compiler ...................... 91 6.2 Direct JIT Compiler Calls ........................... 92 6.3 Circular JIT Cache ............................... 94 7 Evaluation of the JIT Compiler 97 7.1 Execution Performance Evaluation ...................... 98 7.2 Program Size Evaluation ............................ 98 7.2.1 Program Encoding Size Evaluation .................. 98 7.2.2 Virtual Machine and Application Size Evaluation .......... 99 7.3 Benefits of JIT Compilation .......................... 100 7.4 JIT Cache Analysis ............................... 102 7.5 Discussion .................................... 103 8 Reprogramming Sensor Networks with Run-time Compilation 105 8.1 Modelling Reprogramming Overhead ..................... 105 8.2 Modelling the Energy Consumption Lifecycle of Reprogrammed Code .............................. 108 8.3 Including Sensing and Wireless Communication Overheads .................................... 110 8.4 An Experimental Evaluation of Reprogramming with Run-time Compi- lation Techniques ................................ 112 9 Conclusions 117 viii CONTENTS 9.1