45
mbed fest 2013 - Nagoya, Yokohama, Sapporo JPN 13922日日曜日

mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

mbed fest 2013- Nagoya, Yokohama, Sapporo JPN

13年9月22日日曜日

Page 2: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

benefits of running Lightweight Java VM on Cortex-M0+

13年9月22日日曜日

Page 3: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

• Device-independent Development Environment• the “DIY-interpreter” make us unhappy• Lists of Major VM• Why do we need “device-independent”?• RaVem JVM

Agenda

13年9月22日日曜日

Page 4: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

• Device-independent Development Environment• the “DIY-interpreter” make us unhappy• Lists of Major VM• Why do we need “device-independent”?• RaVem JVM•

Agenda

13年9月22日日曜日

Page 5: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

• ex:developers in different layer, different Language

Processor-independent devel. environment

FPGA

Co-processor

CAM

xCommand

Config

CameraLink™

CPU +PowerVR

64bit bus

Peripheral

13年9月22日日曜日

Page 6: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

• ex:developers in different layer, different Language

Processor-independent devel. environment

FPGA

Co-processor

CAM

xCommand

Config

CameraLink™

CPU +PowerVR

64bit bus

Peripheral

C/C++

HDL +Simulink

Java /.net CF

13年9月22日日曜日

Page 7: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

• Device-independent Development Environment• the “DIY-interpreter” make us unhappy• Lists of Major VM• Why do we need “device-independent”?• RaVem JVM

Agenda

13年9月22日日曜日

Page 8: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

the “DIY-interpreter” make us unhappy• “Uh Oh We're In Trouble!”

• Interactive shell or managed code generation• error occurs!

• coding mistake? • or interpreter’s error?• arghhh! I must remake my interpreter!!

• and, You must tell your friends how to use this VM.• OMG!

13年9月22日日曜日

Page 9: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

• Device-independent Development Environment• the “DIY-interpreter” make us unhappy• Lists of Major VM• Why do we need “device-independent”?• RaVem JVM

Agenda

13年9月22日日曜日

Page 10: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

So...• use one’s VM standards

Language for embedded requirementsPython P14P(ex.PyMite) Flash:55kB~,RAM:8kB~

Lua eLua Flash:256kB~,RAM:64kB~

Ruby mruby Flash:512kB,RAM:1MB?

Java Java ME and so on... Flash:130kB,RAM:8kB

13年9月22日日曜日

Page 11: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

VM• use one’s VM standards

JavaVBPythonJavaScriptRubyPerl

13年9月22日日曜日

Page 12: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

VM• use one’s VM standards

54%

13%

12%

7%

7%

7%

Popular VM languages(Tiobe Programming Community,Aug 2013)

JavaVBPythonJavaScriptRubyPerl

13年9月22日日曜日

Page 13: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

Variants Java VM• Java for embedded

JVM System requirementsOracle Java ME Embedded for

STM32F

Flash :130kB~RAM: ? Binary only

uJ Flash :64kB~RAM:192bytes~

thread,runnable,GC,original String type

nanoVM Flash :8kB~RAM: 1kB~

for AVRSingle thread

RaVem Flash :5kB~RAM: 256bytes~

thread,runnable,Integer only

13年9月22日日曜日

Page 14: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

• Device-independent Development Environment• the “DIY-interpreter” make us unhappy• Lists of Major VM• Why do we need “device-independent”?• RaVem JVM

Agenda

13年9月22日日曜日

Page 15: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

• Just C, but each processor needs their unique compiler.

C compiler

ARM

intel

AVR

PIC

Application

13年9月22日日曜日

Page 16: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

• Just C, but each processor needs their unique compiler.

C compiler

Compiler

Compiler

Compiler

Compiler

ARM

intel

AVR

PIC

Application

13年9月22日日曜日

Page 17: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

• Java:Write VM on processor once, same managed code,and run anywhere.

Java

managedcode

ARM

intel

AVR

PIC

VM

13年9月22日日曜日

Page 18: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

• Java:Write VM on processor once, same managed code,and run anywhere.

Java

managedcode

ARM

intel

AVR

PIC

VM

device-independent

13年9月22日日曜日

Page 19: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

• Java:Write VM on processor once, same managed code,and run anywhere.

Java

managedcode

ARM

intel

AVR

PIC

VM

device-independent

write once run anywhere

13年9月22日日曜日

Page 20: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

VM

• How to implementing system that interpret byte code?

• How can we read Java byte code?

13年9月22日日曜日

Page 21: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

reading byte code • Java byte consists...

• Constant Pool• Code

Attribute(instructions)• Exception

• all literal is written in big-endian.

CA FE BA BE.........................................................................................

...........................

...........................

...........................

...........................

...........................

13年9月22日日曜日

Page 22: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

reading byte code • Java byte consists...

• Constant Pool• Code

Attribute(instructions)• Exception

• all literal is written in big-endian.

CA FE BA BE.........................................................................................

...........................

...........................

...........................

...........................

...........................

13年9月22日日曜日

Page 23: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

reading byte code • Java byte consists...

• Constant Pool• Code

Attribute(instructions)• Exception

• all literal is written in big-endian.

CA FE BA BE.........................................................................................

...........................

...........................

...........................

...........................

...........................

13年9月22日日曜日

Page 24: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

reading byte code • Java byte consists...

• Constant Pool• Code

Attribute(instructions)• Exception

• all literal is written in big-endian.

CA FE BA BE.........................................................................................

...........................

...........................

...........................

...........................

...........................

13年9月22日日曜日

Page 25: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

byte code • exam:hello world• Constant pool #20→”hello

world”(for example)

• mnemonics• stack CP#20 to Operand

Stack• call println methods

cp[1]=................cp[20]=”hello world”........

load cp[20],stack call “println”

System.out.println(“hello world”);

13年9月22日日曜日

Page 26: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

byte code • exam:hello world• Constant pool #20→”hello

world”(for example)

• mnemonics• stack CP#20 to Operand

Stack• call println methods

cp[1]=................cp[20]=”hello world”........

load cp[20],stack call “println”

13年9月22日日曜日

Page 27: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

stack• Operand Stack

• First IN, Last OUT...

13年9月22日日曜日

Page 28: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

stack• Operand Stack

• First IN, Last OUT...

data1

data2

data3

13年9月22日日曜日

Page 29: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

stack• Operand Stack

• First IN, Last OUT...

data1data2

data3

13年9月22日日曜日

Page 30: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

example: add • Exam. of Using Operand Stack(Addition)

int x, y, z;

x = 10;y = 20;z = x + y; System.out.println(z);

13年9月22日日曜日

Page 31: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

example: add • Exam. of Using Operand Stack(Addition)

13年9月22日日曜日

Page 32: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

example: add • Exam. of Using Operand Stack(Addition)

1020

13年9月22日日曜日

Page 33: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

example: add • Exam. of Using Operand Stack(Addition)

30

13年9月22日日曜日

Page 34: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

Java VM• Java VM needs only

• Mechanism to quote the Constant Pool,• Mechanism to manage the Operand Stack,• and Mechanism for executing instructions.

13年9月22日日曜日

Page 35: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

Java VM• Java VM needs only

• Mechanism to quote the Constant Pool,• Mechanism to manage the Operand Stack,• and Mechanism for executing instructions.

we’ve just implemented JavaVM on mbed!

13年9月22日日曜日

Page 36: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

• Device-independent Development Environment• the “DIY-interpreter” make us unhappy• Lists of Major VM• Why do we need “device-independent”?• RaVem JVM

Agenda

13年9月22日日曜日

Page 37: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

RaVem JVM

RaVemRaVemRapid VM embbededRapid VM embbeded

• Requirements• Flash 5kbytes or more• RAM 128bytes or more• int type only

• all code written in C (about 700 sloc)

• github (for LPC812)• https://github.com/lynxeyed-atsu/RaVem

• port on mbed• http://mbed.org/users/lynxeyed_atsu/code/FRDM_RaVem_JVM

13年9月22日日曜日

Page 38: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

blink LEDs with JVM• Method of control GPIOs: portWrite(bit, value)

• Write the code Turning a LED on / off

• make that code to work in 4 threads (mbed has 4LEDs)

13年9月22日日曜日

Page 39: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

blink LEDs with JVM• Method of control GPIOs: portWrite(bit, value)

• Write the code Turning a LED on / off

• make that code to work in 4 threads (mbed has 4LEDs) mbed.portWrite(port_bit, 0);

Thread.sleep(time);

mbed.portWrite(port_bit, 1);

Thread.sleep(time);

13年9月22日日曜日

Page 40: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

blink LEDs with JVM• Method of control GPIOs: portWrite(bit, value)

• Write the code Turning a LED on / off

• make that code to work in 4 threads (mbed has 4LEDs) mbed.portWrite(port_bit, 0);

Thread.sleep(time);

mbed.portWrite(port_bit, 1);

Thread.sleep(time);

BlinkLED LED1 = new BlinkLED(0, 90);

BlinkLED LED2 = new BlinkLED(1, 100);

......

Thread th1 = new Thread(LED1);

Thread th2 = new Thread(LED2);

......

th1.start();

th2.start();13年9月22日日曜日

Page 41: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

blink LEDs with JVM• Write VM(.bin file) to mbed.• getting byte code compiling on javac.

• javac make us *.class file.• rename that “Test.cla” (8.3 extension),

• Copy to mbed,• Reset to Start!

public static void main(){int a, b;........

}

CA FE BA BE 00 00 00 32 00 22 07 00 02 01 00 05 48 65 6c 6c 6f 07 00 04 01 00 10 6a

javaccopy

13年9月22日日曜日

Page 42: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

Conclusion• Implemented Java VM to mbed or LPC81x.

• mbed:D&D Java byte code, and execute.• others:make byte code to array, compile together

with ALL JVM code.

• benefits: “write once run anywhere”.

• See also (written in Japanese only..)• http://lynxeyed.hatenablog.com/

13年9月22日日曜日

Page 43: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

Thank you for listening!

13年9月22日日曜日

Page 44: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

Appendix

13年9月22日日曜日

Page 45: mbed fest 2013...Ruby mruby Flash:512kB,RAM:1MB? Java Java ME and so on... Flash:130kB,RAM:8kB 13年9月22日日曜日 VM • use one’s VM standards Java VB Python JavaScript Ruby

RaVem JVM• adding new method named “foobar”

• adding code in invokestatic_callFunction (in ravem.c)

• if(strncmp(func_name,"foobar",6) == 0){.... }

• Adding “fake” methods in Java

• You may not have to write the actual operation. if the method needs return value, you can write just return NULL :-)

13年9月22日日曜日