SlideShare a Scribd company logo
1 of 34
Download to read offline
An ultra-lightweight JavaScript engine
for the Internet of Things
SOSCON 2016
JerryScript
Samsung Electronics | SRUK OSG | Tilmann Scheller
18.11.2016
Introduction
JerryScript
JerryScript Internals Overview
Memory Consumption/Performance
Demo
Future Work
Summary
01
02
03
04
05
06
07
Overview
Introduction
What is JerryScript?
●
A really lightweight JavaScript engine
●
Has a base footprint of ~3KB of RAM
●
Optimized for microcontrollers
●
Originally developed from scratch by Samsung
●
JerryScript is an open source project released under the Apache License
2.0
●
Hosted at the JS Foundation since October 2016
Why JavaScript on microcontrollers?
●
There's a huge pool of JavaScript developers
●
Opens up the possibility for web developers to easily write
software for embedded devices
●
Performance overhead of JavaScript less of an issue for
control tasks
●
Increased productivity, shorter time to market
●
Ability to load code dynamically over the network
JerryScript
JerryScript History
●
Development started in June 2014
●
Released as open source in June 2015
●
JerryScript passed 100% of the test262 conformance test suite in
August 2015
●
Rewritten compact byte code implementation landed in January 2016
●
JerryScript 1.0 released in September 2016
●
Current focus on usability
JerryScript
●
Heavily optimized for a low memory footprint
●
Interpreter-only
●
Compact object representation
●
Compressed pointers
●
No AST, directly creating byte code
●
Compact byte code heavily optimized for low memory
consumption
JerryScript Portability
●
Extremely portable
●
Self-contained
●
Small C library
●
Can run bare-metal
●
Supports the STM32F4, Arduino 101, FRDM-K64F, ESP8266 (experimental)
boards
●
OS support: NuttX, Zephyr, mbed OS, RIOT
●
Runs on Linux/macOS as well
JerryScript
●
Written in C99
●
About 84KLOC
●
Code size 156KB when compiled with GCC in LTO mode for ARM
Thumb-2
●
Implements the entire ECMAScript 5.1 standard, passes 100% of the
test262 conformance test suite
●
C API for embedding JerryScript
●
Byte code snapshot feature
Target hardware
●
STM32F4 developer board
●
Cortex-M4F clocked at 168 MHz
●
192KB of RAM
●
1MB of flash memory
Target hardware
●
Particle Photon board
●
Cortex-M3 clocked at 120 MHz
●
128KB of RAM
●
1MB of flash memory
●
Integrated Wi-Fi
●
Small footprint (37mm x 20mm)
JerryScript Internals Overview
High-Level Design Overview
Parser Overview
●
Optimized for low memory consumption
– E.g. only 41KB of memory is required to parse the 95KB of
concatenated IoT.js source code
●
12.5KB byte code, 10KB literal references,
12.2KB literal storage data, 7KB for parser temporaries
●
Generates byte code directly
– No intermediate representation (e.g. AST)
●
Recursive descent parser
– The parser uses a byte array for the parser stack
instead of calling functions recursively
Compact Byte Code (CBC)
●
CBC is a variable-length byte code
●
Currently 306 opcodes are defined
– Majority of the opcodes are variants of the same operation
●
E.g. “this.name” is a frequent expression in JavaScript so
an opcode is defined to resolve this expression
– Usually this operation is constructed from multiple opcodes:
op_load_this, op_load_name, op_resolve
– Other examples: “a.b(c,d)” or “i++”
Compact Byte Code Interpreter
●
The interpreter is a combination of a register and stack
machine
– The stack is used to compute temporary values
– The registers are used to store local variables
●
Byte code decompression
– Byte code instructions are decoded into a maximum of three atomic
instructions and those instructions are executed by the interpreter
Compressed Pointers
●
Compressed pointers are 16-bit values, which represent
8 byte aligned addresses on the JerryScript heap
– Saves 50% of memory on 32-bit systems
●
The JerryScript heap is a linear memory space with a maximum
size of 512KB (equals to UINT16_MAX * 8)
– UINT16_MAX = 65535
●
Pointer compression can also be turned off to enable a
maximum heap size of 4GB
Value Representation
●
JavaScript is a dynamically typed language
– All values carry type information as well
●
ECMAScript values in JerryScript are 32-bit wide
– They can be primitive values (true, null, undefined, …)
or pointers to numbers, strings or objects
●
On 32-bit systems, 29 bits are enough to directly store
any 8 byte aligned 32-bit pointer
String Representation
●
String descriptor is 8 bytes long
●
Several string types are supported in
JerryScript besides the usual character array
– Short strings: Stored in the 32-bit value field
– Magic (frequently used) string indices
Number Representation
●
Numbers are double precision values by
default
●
Optional mode for single precision values
– Single precision numbers do not satisfy the
ECMAScript requirements but can be computed faster,
trading precision for performance
Object Representation
●
Garbage collector can visit all existing objects
●
Objects have a property list
– Named data, named accessor properties
– Internal properties
●
Functions are objects in JavaScript
Memory Consumption/Performance
SunSpider 1.0.2 - Memory Consumption
3d-cube
3d-raytrace
access-binary-trees
access-fannkuch
access-nbody
bitops-3bit-bits-in-byte
bitops-bits-in-byte
bitops-bitwise-and
bitops-nsieve-bits
controlflow-recursive
crypto-aes
crypto-md5
crypto-sha1
date-format-tofte
date-format-xparb
math-cordic
math-partial-sums
math-spectral-norm
string-base64
string-fasta
0 50 100 150 200 250 300 350 400
35
185
38
11
11
5
5
4
139
80
57
142
92
21
21
6
5
12
125
20
138
339
160
101
106
98
97
97
207
135
190
261
169
352
147
102
101
102
267
107
JerryScript 1.0
Duktape 1.5.1
Max RSS in KB (lower is better)
Measured on a Raspberry Pi 2
SunSpider 1.0.2 - Performance
3d-cube
3d-raytrace
access-binary-trees
access-fannkuch
access-nbody
bitops-3bit-bits-in-byte
bitops-bits-in-byte
bitops-bitwise-and
bitops-nsieve-bits
controlflow-recursive
crypto-aes
crypto-md5
crypto-sha1
date-format-tofte
date-format-xparb
math-cordic
math-partial-sums
math-spectral-norm
string-base64
string-fasta
0 1 2 3 4 5 6 7 8
0.94
1.11
0.59
2.38
1.08
0.58
0.85
1.01
1.8
0.38
1.11
0.73
0.7
0.87
0.47
1.33
0.73
0.58
2.06
1.39
1.01
1.62
1.23
2.19
1.65
1.51
1.71
7.4
2.88
1.13
1.76
1.44
1.33
3.08
1.64
2.56
2.69
0.83
4.18
4.53
JerryScript 1.0
Duktape 1.5.1
Execution time in seconds (lower is better)
Measured on a Raspberry Pi 2
Demo
Pong Demo
●
Implementation of the classic Pong game
●
Display shared across two devices
●
Each device drives one LED matrix
●
Implemented as a Node.js module
●
"AI" oppenent running on the microcontroller
Pong Demo
Raspberry Pi 2
(1GB RAM, 8GB Flash)
Pong Client
Node.js
V8
Linux
STM32F4 board
(192KB RAM, 1MB Flash)
Pong Server
IoT.js
JerryScript
NuttX
Ethernet
USB Keypad
LED Matrix LED Matrix
I2C I2C
Pong Demo
Future Work
Future Work
●
Further performance and memory optimizations
●
Debugging support
●
Memory profiling
●
Selected ES6 features
●
Support for more boards
Summary
Summary
●
Significantly lowers the barrier of entry for JavaScript
development targeting heavily constrained embedded devices
●
Speeds up development
●
Active community
●
More information on http://jerryscript.net
●
Looking for bug reports and feedback
Copyright 2016 SAMSUNG ELECTRONICS. ALL RIGHTS RESERVEDⓒ
THANK YOU

More Related Content

What's hot

Linux-wpan: IEEE 802.15.4 and 6LoWPAN in the Linux Kernel - BUD17-120
Linux-wpan: IEEE 802.15.4 and 6LoWPAN in the Linux Kernel - BUD17-120Linux-wpan: IEEE 802.15.4 and 6LoWPAN in the Linux Kernel - BUD17-120
Linux-wpan: IEEE 802.15.4 and 6LoWPAN in the Linux Kernel - BUD17-120
Linaro
 

What's hot (20)

Rapid SPi Device Driver Development over USB
Rapid SPi Device Driver Development over USBRapid SPi Device Driver Development over USB
Rapid SPi Device Driver Development over USB
 
Clang: More than just a C/C++ Compiler
Clang: More than just a C/C++ CompilerClang: More than just a C/C++ Compiler
Clang: More than just a C/C++ Compiler
 
Easy IoT with JavaScript
Easy IoT with JavaScriptEasy IoT with JavaScript
Easy IoT with JavaScript
 
IoT: From Arduino Microcontrollers to Tizen Products using IoTivity
IoT: From Arduino Microcontrollers to Tizen Products using IoTivityIoT: From Arduino Microcontrollers to Tizen Products using IoTivity
IoT: From Arduino Microcontrollers to Tizen Products using IoTivity
 
Development Boards for Tizen IoT
Development Boards for Tizen IoTDevelopment Boards for Tizen IoT
Development Boards for Tizen IoT
 
Introduction to Linux-wpan and Potential Collaboration
Introduction to Linux-wpan and Potential CollaborationIntroduction to Linux-wpan and Potential Collaboration
Introduction to Linux-wpan and Potential Collaboration
 
IoTivity for Automotive IoT Interoperability
IoTivity for Automotive IoT InteroperabilityIoTivity for Automotive IoT Interoperability
IoTivity for Automotive IoT Interoperability
 
Run Your Own 6LoWPAN Based IoT Network
Run Your Own 6LoWPAN Based IoT NetworkRun Your Own 6LoWPAN Based IoT Network
Run Your Own 6LoWPAN Based IoT Network
 
webthing-floss-iot-20180607rzr
webthing-floss-iot-20180607rzrwebthing-floss-iot-20180607rzr
webthing-floss-iot-20180607rzr
 
Introduction to IoT.JS
Introduction to IoT.JSIntroduction to IoT.JS
Introduction to IoT.JS
 
A Close Look at ARM Code Size
A Close Look at ARM Code SizeA Close Look at ARM Code Size
A Close Look at ARM Code Size
 
6LoWPAN: An Open IoT Networking Protocol
6LoWPAN: An Open IoT Networking Protocol6LoWPAN: An Open IoT Networking Protocol
6LoWPAN: An Open IoT Networking Protocol
 
IoTivity Tutorial: Prototyping IoT Devices on GNU/Linux
IoTivity Tutorial: Prototyping IoT Devices on GNU/LinuxIoTivity Tutorial: Prototyping IoT Devices on GNU/Linux
IoTivity Tutorial: Prototyping IoT Devices on GNU/Linux
 
Linux-wpan: IEEE 802.15.4 and 6LoWPAN in the Linux Kernel - BUD17-120
Linux-wpan: IEEE 802.15.4 and 6LoWPAN in the Linux Kernel - BUD17-120Linux-wpan: IEEE 802.15.4 and 6LoWPAN in the Linux Kernel - BUD17-120
Linux-wpan: IEEE 802.15.4 and 6LoWPAN in the Linux Kernel - BUD17-120
 
Where is LLVM Being Used Today?
Where is LLVM Being Used Today? Where is LLVM Being Used Today?
Where is LLVM Being Used Today?
 
Deploy STM32 family on Zephyr - SFO17-102
Deploy STM32 family on Zephyr - SFO17-102Deploy STM32 family on Zephyr - SFO17-102
Deploy STM32 family on Zephyr - SFO17-102
 
Linaro Connect San Francisco 2017 - Welcome Keynote by George Grey | #SFO17
Linaro Connect San Francisco 2017 - Welcome Keynote by George Grey | #SFO17Linaro Connect San Francisco 2017 - Welcome Keynote by George Grey | #SFO17
Linaro Connect San Francisco 2017 - Welcome Keynote by George Grey | #SFO17
 
BUD17-104: Scripting Languages in IoT: Challenges and Approaches
BUD17-104: Scripting Languages in IoT: Challenges and ApproachesBUD17-104: Scripting Languages in IoT: Challenges and Approaches
BUD17-104: Scripting Languages in IoT: Challenges and Approaches
 
George Grey Welcome Keynote - BUD17-100K1
George Grey Welcome Keynote - BUD17-100K1George Grey Welcome Keynote - BUD17-100K1
George Grey Welcome Keynote - BUD17-100K1
 
Upstreaming 101 - SFO17-TR02
Upstreaming 101 - SFO17-TR02Upstreaming 101 - SFO17-TR02
Upstreaming 101 - SFO17-TR02
 

Similar to SOSCON 2016 JerryScript

mloc.js 2014 - JavaScript and the browser as a platform for game development
mloc.js 2014 - JavaScript and the browser as a platform for game developmentmloc.js 2014 - JavaScript and the browser as a platform for game development
mloc.js 2014 - JavaScript and the browser as a platform for game development
David Galeano
 

Similar to SOSCON 2016 JerryScript (20)

FOSDEM 2019: M3, Prometheus and Graphite with metrics and monitoring in an in...
FOSDEM 2019: M3, Prometheus and Graphite with metrics and monitoring in an in...FOSDEM 2019: M3, Prometheus and Graphite with metrics and monitoring in an in...
FOSDEM 2019: M3, Prometheus and Graphite with metrics and monitoring in an in...
 
OSMC 2018 | Learnings, patterns and Uber’s metrics platform M3, open sourced ...
OSMC 2018 | Learnings, patterns and Uber’s metrics platform M3, open sourced ...OSMC 2018 | Learnings, patterns and Uber’s metrics platform M3, open sourced ...
OSMC 2018 | Learnings, patterns and Uber’s metrics platform M3, open sourced ...
 
Python Generators
Python GeneratorsPython Generators
Python Generators
 
Js on-microcontrollers
Js on-microcontrollersJs on-microcontrollers
Js on-microcontrollers
 
IBM Runtimes Performance Observations with Apache Spark
IBM Runtimes Performance Observations with Apache SparkIBM Runtimes Performance Observations with Apache Spark
IBM Runtimes Performance Observations with Apache Spark
 
Apache Spark Performance Observations
Apache Spark Performance ObservationsApache Spark Performance Observations
Apache Spark Performance Observations
 
cachegrand: A Take on High Performance Caching
cachegrand: A Take on High Performance Cachingcachegrand: A Take on High Performance Caching
cachegrand: A Take on High Performance Caching
 
Netflix Open Source Meetup Season 4 Episode 2
Netflix Open Source Meetup Season 4 Episode 2Netflix Open Source Meetup Season 4 Episode 2
Netflix Open Source Meetup Season 4 Episode 2
 
NetflixOSS Meetup season 3 episode 1
NetflixOSS Meetup season 3 episode 1NetflixOSS Meetup season 3 episode 1
NetflixOSS Meetup season 3 episode 1
 
mloc.js 2014 - JavaScript and the browser as a platform for game development
mloc.js 2014 - JavaScript and the browser as a platform for game developmentmloc.js 2014 - JavaScript and the browser as a platform for game development
mloc.js 2014 - JavaScript and the browser as a platform for game development
 
Node.js Web Apps @ ebay scale
Node.js Web Apps @ ebay scaleNode.js Web Apps @ ebay scale
Node.js Web Apps @ ebay scale
 
Skiron - Experiments in CPU Design in D
Skiron - Experiments in CPU Design in DSkiron - Experiments in CPU Design in D
Skiron - Experiments in CPU Design in D
 
Heterogeneous multiprocessing on androd and i.mx7
Heterogeneous multiprocessing on androd and i.mx7Heterogeneous multiprocessing on androd and i.mx7
Heterogeneous multiprocessing on androd and i.mx7
 
Introduction to DPDK
Introduction to DPDKIntroduction to DPDK
Introduction to DPDK
 
Scalable Monitoring Using Prometheus with Apache Spark Clusters with Diane F...
 Scalable Monitoring Using Prometheus with Apache Spark Clusters with Diane F... Scalable Monitoring Using Prometheus with Apache Spark Clusters with Diane F...
Scalable Monitoring Using Prometheus with Apache Spark Clusters with Diane F...
 
High performance json- postgre sql vs. mongodb
High performance json- postgre sql vs. mongodbHigh performance json- postgre sql vs. mongodb
High performance json- postgre sql vs. mongodb
 
A Journey into Hexagon: Dissecting Qualcomm Basebands
A Journey into Hexagon: Dissecting Qualcomm BasebandsA Journey into Hexagon: Dissecting Qualcomm Basebands
A Journey into Hexagon: Dissecting Qualcomm Basebands
 
Scaling ELK Stack - DevOpsDays Singapore
Scaling ELK Stack - DevOpsDays SingaporeScaling ELK Stack - DevOpsDays Singapore
Scaling ELK Stack - DevOpsDays Singapore
 
module01.ppt
module01.pptmodule01.ppt
module01.ppt
 
[OpenStack Days Korea 2016] Track3 - OpenStack on 64-bit ARM with X-Gene
[OpenStack Days Korea 2016] Track3 - OpenStack on 64-bit ARM with X-Gene[OpenStack Days Korea 2016] Track3 - OpenStack on 64-bit ARM with X-Gene
[OpenStack Days Korea 2016] Track3 - OpenStack on 64-bit ARM with X-Gene
 

More from Samsung Open Source Group

More from Samsung Open Source Group (12)

The Complex IoT Equation (and FLOSS solutions)
The Complex IoT Equation (and FLOSS solutions)The Complex IoT Equation (and FLOSS solutions)
The Complex IoT Equation (and FLOSS solutions)
 
Spawny: A New Approach to Logins
Spawny: A New Approach to LoginsSpawny: A New Approach to Logins
Spawny: A New Approach to Logins
 
IoTivity: Smart Home to Automotive and Beyond
IoTivity: Smart Home to Automotive and BeyondIoTivity: Smart Home to Automotive and Beyond
IoTivity: Smart Home to Automotive and Beyond
 
IoTivity for Automotive: meta-ocf-automotive tutorial
IoTivity for Automotive: meta-ocf-automotive tutorialIoTivity for Automotive: meta-ocf-automotive tutorial
IoTivity for Automotive: meta-ocf-automotive tutorial
 
GENIVI + OCF Cooperation
GENIVI + OCF CooperationGENIVI + OCF Cooperation
GENIVI + OCF Cooperation
 
Open Source Metrics to Inform Corporate Strategy
Open Source Metrics to Inform Corporate StrategyOpen Source Metrics to Inform Corporate Strategy
Open Source Metrics to Inform Corporate Strategy
 
IoTivity: From Devices to the Cloud
IoTivity: From Devices to the CloudIoTivity: From Devices to the Cloud
IoTivity: From Devices to the Cloud
 
Toward "OCF Automotive" profile
Toward "OCF Automotive" profileToward "OCF Automotive" profile
Toward "OCF Automotive" profile
 
OIC AGL Collaboration
OIC AGL CollaborationOIC AGL Collaboration
OIC AGL Collaboration
 
Tizen Connected with IoTivity
Tizen Connected with IoTivityTizen Connected with IoTivity
Tizen Connected with IoTivity
 
IoTivity Connects RVI from GENIVI's Develoment Platform to Tizen devices
IoTivity Connects RVI from GENIVI's Develoment Platform to Tizen devicesIoTivity Connects RVI from GENIVI's Develoment Platform to Tizen devices
IoTivity Connects RVI from GENIVI's Develoment Platform to Tizen devices
 
IoTivity on Tizen: How to
IoTivity on Tizen: How toIoTivity on Tizen: How to
IoTivity on Tizen: How to
 

Recently uploaded

%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 

Recently uploaded (20)

SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 

SOSCON 2016 JerryScript

  • 1. An ultra-lightweight JavaScript engine for the Internet of Things SOSCON 2016 JerryScript Samsung Electronics | SRUK OSG | Tilmann Scheller 18.11.2016
  • 2. Introduction JerryScript JerryScript Internals Overview Memory Consumption/Performance Demo Future Work Summary 01 02 03 04 05 06 07 Overview
  • 4. What is JerryScript? ● A really lightweight JavaScript engine ● Has a base footprint of ~3KB of RAM ● Optimized for microcontrollers ● Originally developed from scratch by Samsung ● JerryScript is an open source project released under the Apache License 2.0 ● Hosted at the JS Foundation since October 2016
  • 5. Why JavaScript on microcontrollers? ● There's a huge pool of JavaScript developers ● Opens up the possibility for web developers to easily write software for embedded devices ● Performance overhead of JavaScript less of an issue for control tasks ● Increased productivity, shorter time to market ● Ability to load code dynamically over the network
  • 7. JerryScript History ● Development started in June 2014 ● Released as open source in June 2015 ● JerryScript passed 100% of the test262 conformance test suite in August 2015 ● Rewritten compact byte code implementation landed in January 2016 ● JerryScript 1.0 released in September 2016 ● Current focus on usability
  • 8. JerryScript ● Heavily optimized for a low memory footprint ● Interpreter-only ● Compact object representation ● Compressed pointers ● No AST, directly creating byte code ● Compact byte code heavily optimized for low memory consumption
  • 9. JerryScript Portability ● Extremely portable ● Self-contained ● Small C library ● Can run bare-metal ● Supports the STM32F4, Arduino 101, FRDM-K64F, ESP8266 (experimental) boards ● OS support: NuttX, Zephyr, mbed OS, RIOT ● Runs on Linux/macOS as well
  • 10. JerryScript ● Written in C99 ● About 84KLOC ● Code size 156KB when compiled with GCC in LTO mode for ARM Thumb-2 ● Implements the entire ECMAScript 5.1 standard, passes 100% of the test262 conformance test suite ● C API for embedding JerryScript ● Byte code snapshot feature
  • 11. Target hardware ● STM32F4 developer board ● Cortex-M4F clocked at 168 MHz ● 192KB of RAM ● 1MB of flash memory
  • 12. Target hardware ● Particle Photon board ● Cortex-M3 clocked at 120 MHz ● 128KB of RAM ● 1MB of flash memory ● Integrated Wi-Fi ● Small footprint (37mm x 20mm)
  • 15. Parser Overview ● Optimized for low memory consumption – E.g. only 41KB of memory is required to parse the 95KB of concatenated IoT.js source code ● 12.5KB byte code, 10KB literal references, 12.2KB literal storage data, 7KB for parser temporaries ● Generates byte code directly – No intermediate representation (e.g. AST) ● Recursive descent parser – The parser uses a byte array for the parser stack instead of calling functions recursively
  • 16. Compact Byte Code (CBC) ● CBC is a variable-length byte code ● Currently 306 opcodes are defined – Majority of the opcodes are variants of the same operation ● E.g. “this.name” is a frequent expression in JavaScript so an opcode is defined to resolve this expression – Usually this operation is constructed from multiple opcodes: op_load_this, op_load_name, op_resolve – Other examples: “a.b(c,d)” or “i++”
  • 17. Compact Byte Code Interpreter ● The interpreter is a combination of a register and stack machine – The stack is used to compute temporary values – The registers are used to store local variables ● Byte code decompression – Byte code instructions are decoded into a maximum of three atomic instructions and those instructions are executed by the interpreter
  • 18. Compressed Pointers ● Compressed pointers are 16-bit values, which represent 8 byte aligned addresses on the JerryScript heap – Saves 50% of memory on 32-bit systems ● The JerryScript heap is a linear memory space with a maximum size of 512KB (equals to UINT16_MAX * 8) – UINT16_MAX = 65535 ● Pointer compression can also be turned off to enable a maximum heap size of 4GB
  • 19. Value Representation ● JavaScript is a dynamically typed language – All values carry type information as well ● ECMAScript values in JerryScript are 32-bit wide – They can be primitive values (true, null, undefined, …) or pointers to numbers, strings or objects ● On 32-bit systems, 29 bits are enough to directly store any 8 byte aligned 32-bit pointer
  • 20. String Representation ● String descriptor is 8 bytes long ● Several string types are supported in JerryScript besides the usual character array – Short strings: Stored in the 32-bit value field – Magic (frequently used) string indices
  • 21. Number Representation ● Numbers are double precision values by default ● Optional mode for single precision values – Single precision numbers do not satisfy the ECMAScript requirements but can be computed faster, trading precision for performance
  • 22. Object Representation ● Garbage collector can visit all existing objects ● Objects have a property list – Named data, named accessor properties – Internal properties ● Functions are objects in JavaScript
  • 24. SunSpider 1.0.2 - Memory Consumption 3d-cube 3d-raytrace access-binary-trees access-fannkuch access-nbody bitops-3bit-bits-in-byte bitops-bits-in-byte bitops-bitwise-and bitops-nsieve-bits controlflow-recursive crypto-aes crypto-md5 crypto-sha1 date-format-tofte date-format-xparb math-cordic math-partial-sums math-spectral-norm string-base64 string-fasta 0 50 100 150 200 250 300 350 400 35 185 38 11 11 5 5 4 139 80 57 142 92 21 21 6 5 12 125 20 138 339 160 101 106 98 97 97 207 135 190 261 169 352 147 102 101 102 267 107 JerryScript 1.0 Duktape 1.5.1 Max RSS in KB (lower is better) Measured on a Raspberry Pi 2
  • 25. SunSpider 1.0.2 - Performance 3d-cube 3d-raytrace access-binary-trees access-fannkuch access-nbody bitops-3bit-bits-in-byte bitops-bits-in-byte bitops-bitwise-and bitops-nsieve-bits controlflow-recursive crypto-aes crypto-md5 crypto-sha1 date-format-tofte date-format-xparb math-cordic math-partial-sums math-spectral-norm string-base64 string-fasta 0 1 2 3 4 5 6 7 8 0.94 1.11 0.59 2.38 1.08 0.58 0.85 1.01 1.8 0.38 1.11 0.73 0.7 0.87 0.47 1.33 0.73 0.58 2.06 1.39 1.01 1.62 1.23 2.19 1.65 1.51 1.71 7.4 2.88 1.13 1.76 1.44 1.33 3.08 1.64 2.56 2.69 0.83 4.18 4.53 JerryScript 1.0 Duktape 1.5.1 Execution time in seconds (lower is better) Measured on a Raspberry Pi 2
  • 26. Demo
  • 27. Pong Demo ● Implementation of the classic Pong game ● Display shared across two devices ● Each device drives one LED matrix ● Implemented as a Node.js module ● "AI" oppenent running on the microcontroller
  • 28. Pong Demo Raspberry Pi 2 (1GB RAM, 8GB Flash) Pong Client Node.js V8 Linux STM32F4 board (192KB RAM, 1MB Flash) Pong Server IoT.js JerryScript NuttX Ethernet USB Keypad LED Matrix LED Matrix I2C I2C
  • 31. Future Work ● Further performance and memory optimizations ● Debugging support ● Memory profiling ● Selected ES6 features ● Support for more boards
  • 33. Summary ● Significantly lowers the barrier of entry for JavaScript development targeting heavily constrained embedded devices ● Speeds up development ● Active community ● More information on http://jerryscript.net ● Looking for bug reports and feedback
  • 34. Copyright 2016 SAMSUNG ELECTRONICS. ALL RIGHTS RESERVEDⓒ THANK YOU