FOSDEM2016 - Ruby and OMR

51
Experiments in utilizing OMR technologies in MRI Charlie Gracie January 31, 2016 Ruby and OMR

Transcript of FOSDEM2016 - Ruby and OMR

Page 1: FOSDEM2016 - Ruby and OMR

Experiments in utilizing OMR technologies in MRI

Charlie GracieJanuary 31, 2016

Ruby and OMR

Page 2: FOSDEM2016 - Ruby and OMR

2

Who am I?

Charlie [email protected] @crgracie

• Garbage Collection Architect for IBM J9 JVM

• Current focus on developing technologies for the OMR project

Page 3: FOSDEM2016 - Ruby and OMR

An open source toolkit for language runtime

technologies.

OMR

Page 4: FOSDEM2016 - Ruby and OMR

4

Open Source Toolkit for Building Runtimes

• Eclipse OMR project proposal• https://goo.gl/ZTBoeu

• Will be open sourced under EPL• Derived from the source code of IBM’s

production runtimes

Page 5: FOSDEM2016 - Ruby and OMR

5

Open Source Toolkit for Building Runtimes

• Implements language-agnostic parts of a managed runtime

• Bootstraps development of new runtimes

Page 6: FOSDEM2016 - Ruby and OMR

6

Open Source Toolkit for Building Runtimes

• Allows incremental enablement of advanced functionality

• Consume new features when available• New platforms• GPU• FPGA

Page 7: FOSDEM2016 - Ruby and OMR

7

Open Source Toolkit for Building Runtimes

• Ships as part of IBM SDK for Java 8• Development of IBM SDK for Java 9

consuming OMR daily• Proof-of-concept integration with Ruby

MRI, CPython, SOM++

Page 8: FOSDEM2016 - Ruby and OMR

Execution Environment

Language-Agnostic Components

Platform Abstraction Layer

Garbage Collector

Diagnostic Services

Source Code Bytecode/ASTCompiler

8

Just-In-Time Compiler

InterpreterSource BytecodeCompiler Interpreter

Page 9: FOSDEM2016 - Ruby and OMR

9

Execution Environment

Language-Agnostic Components

Platform Abstraction Layer

Garbage Collector

Diagnostic Services

Source Code Bytecode/ASTCompiler

Just-In-Time Compiler

InterpreterSource BytecodeCompiler Interpreter

Page 10: FOSDEM2016 - Ruby and OMR

10

Gluing it Together

InterpreterBytecode

/AST Compiler

Garbage Collector

GC Glue

Just-In-Time Compiler

JIT Glue

Diagnostic Services

D. Glue

Page 11: FOSDEM2016 - Ruby and OMR

Ruby + OMR Preview

Page 12: FOSDEM2016 - Ruby and OMR

12

Ruby + OMR Preview

• 2 Presentations at Ruby Kaigi 2015• The OMR GC Talk

• http://goo.gl/mA4IUG

• IBM’s Ruby JIT Talk• http://goo.gl/K5ZHY0

Page 13: FOSDEM2016 - Ruby and OMR

13

Ruby + OMR Preview

• GitHub location for the preview• https://goo.gl/P3yXuy

• Available as Docker images• Ruby git clone + OMR changes

included• /home/rubyomr/ruby• No OMR or GLUE source

Page 14: FOSDEM2016 - Ruby and OMR

14

Ruby + OMR Preview

• Currently available on 3 platforms• Linux on x86• Linux on Z• Linux on OpenPOWER

Page 15: FOSDEM2016 - Ruby and OMR

15

Ruby + OMR Preview

• Based on Ruby 2.2.3 • Working to merge with the master branch

• Successfully passes “make test”• Runs rails apps

Page 16: FOSDEM2016 - Ruby and OMR

16

Ruby + OMR Preview

• Integrated OMR components include• Garbage Collection• Just In Time Compilation• Diagnostic Tooling

Page 17: FOSDEM2016 - Ruby and OMR

Garbage Collection

Page 18: FOSDEM2016 - Ruby and OMR

18

OurStrategy:

• Be 100% compatible

Page 19: FOSDEM2016 - Ruby and OMR

19

OurStrategy:

• Be 100% compatible

• Decrease pause times

Page 20: FOSDEM2016 - Ruby and OMR

20

OurStrategy:

• Be 100% compatible

• Decrease pause times

• Increase allocation speed

Page 21: FOSDEM2016 - Ruby and OMR

21

OurStrategy:

• Be 100% compatible

• Decrease pause times

• Increase allocation speed

• Improve object locality

Page 22: FOSDEM2016 - Ruby and OMR

22

100% Compatible

• Do not break C extensions• Pass all tests that ship with MRI• Test 3rd party applications

Page 23: FOSDEM2016 - Ruby and OMR

23

Decrease Pause Times

• Use helper threads to:• Mark roots in parallel• Use OMR work stack to complete scanning

in parallel• Perform object finalization in parallel• Perform sweep operations in parallel

Page 24: FOSDEM2016 - Ruby and OMR

24

Increase Allocation Speed

• Use TLH mechanism from OMR• Threads reserve blocks of heap memory

for exclusive allocation• Threads bump allocate out of these blocks

alloc(rbthread_t thread, int size)if (thread->tlhAlloc < thread->tlhTop - size)

object = thread->tlhAllocthread->tlhAlloc = object + size

elseobject = OMR_GC_Allocate(thread, size);

Page 25: FOSDEM2016 - Ruby and OMR

25

Improve Object Locality

• Create new OMRBuffer object type • Allocate OMRBuffers on heap• Data is regularly adjacent to object in

heap• OMRBuffers are automatically

reclaimed during collection

Page 26: FOSDEM2016 - Ruby and OMR

26

Decrease Pause Times

• OMRBuffers do not require calls to obj_free

• Significant reduction in pause times

Page 27: FOSDEM2016 - Ruby and OMR

27

Future Work

• Improve heap fragmentation• Add support for concurrent marking

Page 28: FOSDEM2016 - Ruby and OMR

Just In Time Compilation

Page 29: FOSDEM2016 - Ruby and OMR

29

OurStrategy:

• Mimic interpreter for maximum compatibility.

• Implement simple opcodes directly in IL

IL

Page 30: FOSDEM2016 - Ruby and OMR

30

OurStrategy:

• Build callbacks to VM for complex opcodes.• Automatically

generate callbacks from the instruction definition file.

IL

callback

Page 31: FOSDEM2016 - Ruby and OMR

31

OurStrategy:

• Fast-path particular patterns• e.g trace

IL

callback

IL

IL

callback

Page 32: FOSDEM2016 - Ruby and OMR

32

OurStrategy:

• Don’t try to handle everything – let interpreter handle hard cases!

IL

callback

IL

IL

callback

Page 33: FOSDEM2016 - Ruby and OMR

Current Status

• Supports almost all opcodes

• Compile iseq after they are executed N times

• Dispatch to JIT code if the iseq has been compiled

Page 34: FOSDEM2016 - Ruby and OMR

34

Future Work

• Speculative optimizations powered by decompilation and code-patching• Class Hierarchy Based Optimization• Guarded inlining• Type Specialization

• Recompilation• Interpreter and JIT Profiling• Asynchronous Compilation• More optimization!

• OMR’s Ruby JIT uses only 10 / 100+ optimizations.

Page 35: FOSDEM2016 - Ruby and OMR

Diagnostic Tooling

Page 36: FOSDEM2016 - Ruby and OMR

36

Garbage Collection and Memory Visualizer

• Provides a graphical details on GC events post mortem from verbose:gc logs

• Works with IBM JDK, IBM Node.js and Ruby OMR Preview

• https://goo.gl/YwNrmI

Page 37: FOSDEM2016 - Ruby and OMR

37

Garbage Collection and Memory Visualizer

Page 38: FOSDEM2016 - Ruby and OMR

38

Health Center

• Provides a live view of runtime details• Works with IBM JDK, IBM Node.js and

Ruby OMR Preview• http://goo.gl/u3VITI

Page 39: FOSDEM2016 - Ruby and OMR

39

Health Center – GC Statistics

Page 40: FOSDEM2016 - Ruby and OMR

40

Health Center – Ruby Method Profiling

Page 41: FOSDEM2016 - Ruby and OMR

Performance Results

Page 42: FOSDEM2016 - Ruby and OMR

42

Ruby 2.2.2 Ruby 2.2.2 + OMR0

20

40

60

80

100

120

140

112.84122.57

Is Ruby Fast Yet?

Page 43: FOSDEM2016 - Ruby and OMR

43

Spee

dup

Rela

tive

to In

terp

rete

rMicro Benchmarks

3x

2x

1x

Page 44: FOSDEM2016 - Ruby and OMR

Ruby 2.2.2 Ruby 2.2.2 + OMR Ruby 2.2.2 + OMR +JIT

0

5

10

15

20

25

30 27.8

16.6

5.3

pow(2,n)

Page 45: FOSDEM2016 - Ruby and OMR

Future?!?!

Page 46: FOSDEM2016 - Ruby and OMR

Future

• More feedback from the community• Is this work interesting?

• We would like to get more involved with the Ruby community now that this work is public.

• If there are parts of OMR that the Ruby community believes would be beneficial we would like to be part of the Ruby 3x3 plan

Page 47: FOSDEM2016 - Ruby and OMR

Possible Ideas For Improvements• Work on removing the GIL

• Improved scaling• But how much code would be broken?

• Improved C extension API• Allow object movement? • Improve JITs ability to apply

optimizations• Again how much code would be

broken?• Implement key class libraries in Ruby

• Significant JIT improvements• How much would this hurt short

running applications?

Page 48: FOSDEM2016 - Ruby and OMR

Thank you!

Page 49: FOSDEM2016 - Ruby and OMR

John DuimovichCTO IBM [email protected]@jduimovich

Contact Info

Mark StoodleyOMR Project [email protected]@mstoodle

49

Charlie GracieOMR GC [email protected]@crgracie

Page 50: FOSDEM2016 - Ruby and OMR

Trademarks, Copyrights, Disclaimers

50

IBM’s statements regarding its plans, directions, and intent are subject to change or withdrawal without notice at IBM’s sole discretion. Information regarding potential future products is intended to outline our general product direction and it should not be relied on in making a purchasing decision. The information mentioned regarding potential future products is not a commitment, promise, or legal obligation to deliver any material, code or functionality. Information about potential future products may not be incorporated into any contract. The development, release, and timing of any future features or functionality described for our products remains at our sole discretion.

IBM, the IBM logo, and ibm.com are trademarks or registered trademarks of International Business Machines Corp., registered in many jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of other IBM trademarks is available on the web at "Copyright and trademark information" at http://www.ibm.com/legal/copytrade.shtml

Other company, product, or service names may be trademarks or service marks of others.

THE INFORMATION CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY. WHILE EFFORTS WERE MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE INFORMATION CONTAINED IN THIS PRESENTATION, IT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. IN ADDITION, THIS INFORMATION IS BASED ON IBM’S CURRENT PRODUCT PLANS AND STRATEGY, WHICH ARE SUBJECT TO CHANGE BY IBM WITHOUT NOTICE. IBM SHALL NOT BE RESPONSIBLE FOR ANY DAMAGES ARISING OUT OF THE USE OF, OR OTHERWISE RELATED TO, THIS PRESENTATION OR ANY OTHER DOCUMENTATION. NOTHING CONTAINED IN THIS PRESENTATION IS INTENDED TO, NOR SHALL HAVE THE EFFECT OF, CREATING ANY WARRANTIES OR REPRESENTATIONS FROM IBM (OR ITS SUPPLIERS OR LICENSORS), OR ALTERING THE TERMS AND CONDITIONS OF ANY AGREEMENT OR LICENSE GOVERNING THE USE OF IBM PRODUCTS OR SOFTWARE.

© Copyright International Business Machines Corporation 2015. All rights reserved.

Page 51: FOSDEM2016 - Ruby and OMR

51

Additional Important Disclaimers

• THE INFORMATION CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY.

• WHILST EFFORTS WERE MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE INFORMATION CONTAINED IN THIS PRESENTATION, IT IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.

• ALL PERFORMANCE DATA INCLUDED IN THIS PRESENTATION HAVE BEEN GATHERED IN A CONTROLLED ENVIRONMENT. YOUR OWN TEST RESULTS MAY VARY BASED ON HARDWARE, SOFTWARE OR INFRASTRUCTURE DIFFERENCES.

• ALL DATA INCLUDED IN THIS PRESENTATION ARE MEANT TO BE USED ONLY AS A GUIDE.• IN ADDITION, THE INFORMATION CONTAINED IN THIS PRESENTATION IS BASED ON IBM’S CURRENT

PRODUCT PLANS AND STRATEGY, WHICH ARE SUBJECT TO CHANGE BY IBM, WITHOUT NOTICE. • IBM AND ITS AFFILIATED COMPANIES SHALL NOT BE RESPONSIBLE FOR ANY DAMAGES ARISING OUT OF

THE USE OF, OR OTHERWISE RELATED TO, THIS PRESENTATION OR ANY OTHER DOCUMENTATION. • NOTHING CONTAINED IN THIS PRESENTATION IS INTENDED TO, OR SHALL HAVE THE EFFECT OF: • - CREATING ANY WARRANT OR REPRESENTATION FROM IBM, ITS AFFILIATED COMPANIES OR ITS OR

THEIR SUPPLIERS AND/OR LICENSORS