VA Smalltalk 9: Exploring the next-gen LLVM-based virtual machine

Similar documents
FTL WebKit s LLVM based JIT

LECTURE 2. Compilers and Interpreters

CS 261 Fall Machine and Assembly Code. Data Movement and Arithmetic. Mike Lam, Professor

Lecture 3 CIS 341: COMPILERS

How Software Executes

Inside VMProtect. Introduction. Internal. Analysis. VM Logic. Inside VMProtect. Conclusion. Samuel Chevet. 16 January 2015.

Compiler Construction: LLVMlite

Machine Program: Procedure. Zhaoguo Wang

McSema: Static Translation of X86 Instructions to LLVM

The JavaScriptCore Virtual Machine. Filip Pizlo Apple Inc.

Expressing high level optimizations within LLVM. Artur Pilipenko

BEAMJIT, a Maze of Twisty Little Traces

Accelerating Ruby with LLVM

x86 Programming I CSE 351 Winter

Machine/Assembler Language Putting It All Together

15-411: LLVM. Jan Hoffmann. Substantial portions courtesy of Deby Katz

Machine Programming 3: Procedures

VA Smalltalk Update. 24 th ESUG Conference Prague, Czech Republic August 23, John O Keefe Chief Technical Officer Instantiations, Inc.

The Stack & Procedures

6.035 Project 3: Unoptimized Code Generation. Jason Ansel MIT - CSAIL

Don t Get Caught In the Cold, Warm-up Your JVM Understand and Eliminate JVM Warm-up Overhead in Data-parallel Systems

The Stack & Procedures

CSc 453 Interpreters & Interpretation

Meta-Programming and JIT Compilation

Control-flow Enforcement Technology H.J. Lu. Intel November, 2018

Parsing Scheme (+ (* 2 3) 1) * 1

Where We Are. Optimizations. Assembly code. generation. Lexical, Syntax, and Semantic Analysis IR Generation. Low-level IR code.

Assembly Language: Function Calls

BEAMJIT: An LLVM based just-in-time compiler for Erlang. Frej Drejhammar

Running class Timing on Java HotSpot VM, 1

x86 64 Programming I CSE 351 Autumn 2018 Instructor: Justin Hsia

Assembly Programming IV

Pointer Analysis for C/C++ with cclyzer. George Balatsouras University of Athens

Princeton University Computer Science 217: Introduction to Programming Systems. Assembly Language: Function Calls

Optimization Techniques

Machine-level Programs Procedure

Targeting LLVM IR. LLVM IR, code emission, assignment 4

CS429: Computer Organization and Architecture

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 4

MACHINE LEVEL PROGRAMMING 1: BASICS

Truffle A language implementation framework

Lecture 2 Overview of the LLVM Compiler

Sequence 5.1 Building stack frames in LLVM

Compiling Techniques

Inception: System-Wide Security Testing of Real- World Embedded Systems Software Nassim Corteggiani (Maxim Integrated / EURECOM) Giovanni Camurati

Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition. Carnegie Mellon

CSC 252: Computer Organization Spring 2018: Lecture 6

CS5460: Operating Systems

x86-64 Programming III & The Stack

Compiler construction 2009

LLVM and IR Construction

CPSC 261 Midterm 1 Tuesday February 9th, 2016

Compilers Crash Course

CS429: Computer Organization and Architecture

Machine-Level Programming (2)

CIS 341 Midterm March 2, 2017 SOLUTIONS

Swift: A Register-based JIT Compiler for Embedded JVMs

Assembly Language II: Addressing Modes & Control Flow

LLV8: Adding LLVM as an extra JIT tier to V8 JavaScript engine

Machine-Level Programming III: Procedures

CSE351 Spring 2018, Midterm Exam April 27, 2018

Java and C II. CSE 351 Spring Instructor: Ruth Anderson

Towards Ruby3x3 Performance

Stack Frame Components. Using the Stack (4) Stack Structure. Updated Stack Structure. Caller Frame Arguments 7+ Return Addr Old %rbp

Getting started. Roel Jordans

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan

a translator to convert your AST representation to a TAC intermediate representation; and

CS 12 Fall 2003 Solutions for mid-term exam #2

x86 Assembly Crash Course Don Porter

C to Machine Code x86 basics: Registers Data movement instructions Memory addressing modes Arithmetic instructions

Generation. representation to the machine

Lecture 3 Overview of the LLVM Compiler

CSE 401/M501 Compilers

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

Practical Malware Analysis

Accelerating Stateflow With LLVM

A Trace-based Java JIT Compiler Retrofitted from a Method-based Compiler

Intermediate Representations

Compilers and Code Optimization EDOARDO FUSELLA

Dynamic Binary Instrumentation: Introduction to Pin

Background: Operating Systems

CSE 401/M501 Compilers

Machine Level Programming: Basics

Usually, target code is semantically equivalent to source code, but not always!

The von Neumann Machine

Baggy bounds with LLVM

CSC 252: Computer Organization Spring 2018: Lecture 5

VA Smalltalk Update. 10 th Smalltalks Conference Tucuman, Argentina November 9-11, John O Keefe Chief Technical Officer Instantiations, Inc.

Computer Components. Software{ User Programs. Operating System. Hardware

Intermediate Representations

Registers. Ray Seyfarth. September 8, Bit Intel Assembly Language c 2011 Ray Seyfarth

x86 Programming I CSE 351 Autumn 2016 Instructor: Justin Hsia

Machine-Level Programming II: Control

CS 261 Fall Mike Lam, Professor. x86-64 Control Flow

LLVM for a Managed Language What we've learned

Assembly II: Control Flow. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

CSc 520 Principles of Programming Languages

+ Machine Level Programming: x86-64 History

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program.

Winter Compiler Construction T11 Activation records + Introduction to x86 assembly. Today. Tips for PA4. Today:

Transcription:

2017 FAST Conference La Plata, Argentina November, 2017 VA Smalltalk 9: Exploring the next-gen LLVM-based virtual machine Alexander Mitin Senior Software Engineer Instantiations, Inc.

The New VM Runtime 64-bit & 32-bit Written from scratch Compatibility & Performance LLVM is a core tech

Traditional Way Written in C or C++ Interpreter is a huge case statement Or a huge function with lots of labels Lots of overhead Support for JIT is complicated

Options? Continue to develop using legacy tools? Use assembly language? Develop a special language for building a VM?

Let s C A typical C language compiler has these stages: Preprocessor Code parsing Building some intermediate representation Optimizations Machine code generation Output to an object file

Let s C A typical C language compiler has these stages: Preprocessor Code parsing Building some intermediate representation Optimizations Machine code generation Output to an object file

LLVM Can Do it LLVM is a compiler infrastructure Advanced IR Object file generation Open-source with big community Capable for JIT

Instantiations Way Written in LLVM IR Every bytecode handler is a function Fine-tuned using LLVM intrinsics and attrs Minimized overhead Transparent interpreter-jit transitions

A bytecode 01 I_32 BCpushMagicB(VMContext* vmstruct, oop** sp, I_8* pc) 02 { 03 I_PTR operand = (I_PTR)*pc++; // load a bytecode operand 04 *--sp = (oop*)operand; // store it to a stack slot and advance sp 05 I_8 nextbc = *pc++; // get next bytecode 06 BCFuncType* nexthandler = bytecodetable[nextbc];// get next bytecode handler function 07 return nexthandler(vmstruct, sp, pc) // call it 08 }

LLVM Crash Course Modules & Functions Basic Blocks SSA form

A bytecode 01 define internal cc18 i32 @BCpushMagicB(%VMContext* inreg %vmstruct, %oop** inreg %sp, i8* inreg %pc) #1 align 8 02 { 03 %1 = load i8, i8* %pc, align 1 04 %2 = sext i8 %1 to i64 05 %3 = getelementptr inbounds i8, i8* %pc, i64 1 06 %4 = inttoptr i64 %2 to %oop* 07 %5 = getelementptr %oop*, %oop** %sp, i64-1 08 store %oop* %4, %oop** %5 09 %6 = load i8, i8* %3 10 %7 = zext i8 %6 to i64 11 %8 = getelementptr inbounds i8, i8* %3, i64 1 12 %9 = getelementptr inbounds @bytecodetable, i64 0, i64 %7 13 %10 = load BCFuncType*, BCFuncType** %9, align 8 14 %11 = tail call cc18 i32 %10(%VMContext* inreg %vmstruct, %oop** inreg %5, i8* inreg %8) 15 ret i32 %11 16 }

A bytecode 01 void EsVMBytecodes::pushMagic(IRBuilder<>& b, Value* sp, Value* pc, Value* bp, EsBCOpType bcot) 02 { 03 Value *operand; 04 Value *currentpc = getnext(b, pc, bcot, operand); 05 Value *currentsp = stackpush(b, sp, operand); 06 executenextbytecode(b, currentsp, currentpc, bp); 07 }

A bytecode 00 BCpushMagicB: 01 movsbq (%rsi), %rax ; load bytecode operand from pc 02 movq %rax, -8(%r15) ; store it into a stack slot 03 addq $-8, %r15 ; advance stack pointer 04 movzbl 1(%rsi), %eax ; get next bytecode from pc + 1 05 addq $2, %rsi ; advance pc by 2 06 movabsq $bytecodetable, %rcx 07 rex64 jmpq *(%rcx,%rax,8) ; indirect jump to the next bytecode handler

The Idea LLVM tail-call elimination optimization Keep performance-critical data in CPU regs

Method Exec: Interpreted // a pseudo-code I_32 methodexec(vmcontext*, I_PTR arg1, I_PTR arg2) { AllocateStackFrame(ftInterpreted); return ExecuteNextBytecode(arg2); // tail-call }

Method Exec: Native // a pseudo-code I_32 methodexec(vmcontext*, I_PTR arg1, I_PTR arg2) { AllocateStackFrame(ftNative); // execute JIT-generated native code in place }

Memory Manager Written in C from scratch So far the same algorithm as it was in v.8 It s ready for modifications

Build System CMake based MinGW64/gcc compiler A special app with LLVM IR MinGW64/gcc linker

Future Work Unicode support Alternative memory manager with parallel GC Alternative JIT engine (OMR?) Make use of CPU s stack pointer register Compressed OOPs

Thank you for your attention Questions? Contacts: E-mail: amitin@instantiations.com GitHub: amitin