SlideShare une entreprise Scribd logo
1  sur  33
Télécharger pour lire hors ligne
Metascala
A tiny DIY JVM
https://github.com/lihaoyi/Metascala
Li Haoyi
haoyi@dropbox.com
Scala Exchange
2nd Dec 2013
Who am I?
Li Haoyi
Write Python during the day
Write Scala at night
What is Metascala?
● A JVM
● in 3000 lines of Scala
● Which can load & interpret java programs
● And can interpret itself!
Size comparison
● Metascala:

~3,000 lines

● Avian JVM: ~80,000 lines
● OpenJDK:

~1,000,000 lines
Basic Usage

Create a new metascala VM
Plain Old Java Object

Captured variables are serialized
into VM’s environment

Closure’s class file
is given to VM to
load/parse/execute
Result is extracted
from VM into host
environment
No global state

Any other classes necessary to
evaluate the closure are loaded
from the current Classpath
It’s Metacircular!

Need to give the outer VM more
than the 1mb default heap

VM inside
a VM!
Simpler program avoids
initializing the scala/java std
libraries, which takes forever
under double-interpretation.

Takes a while (~10s) to produce result
Limitations
● Single-threaded
● Limited IO
● Slowww
Performance Comparison
● OpenJDK:

1.0x

● Metascala:

~100x

● Meta-Metascala: ~10000x
Why Metascala?
● Fun to explore the innards of the JVM
● An almost-fully secure Java runtime!
● Small size makes fiddling fun
Why Metascala?
● Fun to explore the innards of the JVM
● An almost-fully secure Java runtime!
● Small size makes fiddling fun
Quick Tour

Immutable Defs: ~380 loc
Native Bindings: ~650 loc
Bytecode SSA transform: ~650 loc
Runtime data structures:
820 loc
Binary heap & Copying
GC: 132 loc
DIY scala-pickling: 132 loc
“This is a VM”: 243 loc
Quick Tour: Tests
Tests for basic Java features

GC Fuzz-tests
Test Metacircularity!
Scala std lib usage
What’s a Heap?

Fig 1. A Heap
What’s a Garbage Collector?
Blit (copy) all roots to new heap
Stop when you’ve
scanned everything

Not pseudocode

Scan the already
copied things for
more things and
copy them too
Why Metascala?
● Fun to explore the innards of the JVM
● An almost-fully secure Java runtime!
● Small size makes fiddling fun
Limited Instruction Count
And Limited Memory!

Not an OOM Error!
We throw this ourselves
Explicitly defined capabilities

Every external call has to
be explicitly defined and
enabled
Security Characteristics
●
●
●
●

Finite instruction count
Finite memory
Well-defined interface to outside world
Doesn’t rely on Java Security Model at all!

● Still some holes…
Security Holes
●
●
●
●
●

Classloader can read from anywhere
Time spent classloading not accounted
Memory spent on classes not accounted
GC time not accounted
“native” methods’ time/memory not
accounted
Basic Problem
Outside World

User code resource
consumption is bounded
VM’s runtime resource
usage can be made to
grow arbitrarily large

Classes
Native method calls
User
Code
Runtime Data
Structures
Garbage Collector
Possible Solution
Put a VM Inside a VM!
Works,
... but 10000x slowdown

Outside World
Fixed Unaccounted Costs
Outside World

Classes
Native method calls
User
Code
Runtime Data
Structures
Garbage Collector
Another Possible Solution
Move more components into
virtual runtime
Difficult to bootstrap correctly
WIP

Outside World
Native method calls
Classes
Garbage
Collector
User Code
Runtime Data
Structures
Why Metascala?
● Fun to explore the innards of the JVM
● An almost-fully secure Java runtime!
● Small size makes fiddling fun
Live Demo
Ugliness
● Long compile times
● Nasty JVM Interface
● Impossible Debugging
Long compile times
●
● 100 lines/s
● Twice as slow (50 lines/s) on my older
machine!
Nasty JVM Interface
Ideal World
Initialized
User Code

Real World
Linear Initialization

Std Library

Initialized
User Code
Std Library

Clean Interfaces
VM

VM

LazyInitialization
means repeated
dives back into
lib/native code
Nasty Language
VM Interface
Java’s dirty little secret
The Verbosity of Java with the Safety of C

WTF! I’d never use these things!
You probably do What happens if you don’t have
them

Almost every Java program
ever uses these things.
Next Steps
● Maximize correctness
○ Implement Threads & IO
○ Fix bugs (GC, native calls, etc.)

● Solidify security characteristics
○ Still plenty of unaccounted-for memory/processing
○ Some can be hosted “within” VM itself

● Simplify Std-Lib/VM interface
○ Try using Android Std Lib?
Possible Experiments
● Native codegen instead of an interpreter?
○ Generate/exec native code through JNI
○ Heap is already a binary blob that can be easily
passed to native code

● Bytecode transforms and optimizations?
○ Already in SSA form

● Continuations, Isolates, Value Classes?
● Port the whole thing to Scala.Js?
Metascala: a tiny DIY JVM
Ask me about:
● Single Static Assignment form
● Copying Garbage Collection
● sun.misc.Unsafe
● Warts of the .class file format
● Capabilities-based security
● Abandoned approaches

Contenu connexe

Tendances

JVM, byte codes & jvm languages
JVM, byte codes & jvm languagesJVM, byte codes & jvm languages
JVM, byte codes & jvm languagesEdgar Espina
 
Node.js Course 1 of 2 - Introduction and first steps
Node.js Course 1 of 2 - Introduction and first stepsNode.js Course 1 of 2 - Introduction and first steps
Node.js Course 1 of 2 - Introduction and first stepsManuel Eusebio de Paz Carmona
 
Ola Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The JvmOla Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The Jvmdeimos
 
Java Virtual Machine
Java Virtual Machine Java Virtual Machine
Java Virtual Machine profbnk
 
Java introduction with JVM architecture
Java introduction with JVM architectureJava introduction with JVM architecture
Java introduction with JVM architectureatozknowledge .com
 
Double checkedlockingjavasingletons
Double checkedlockingjavasingletonsDouble checkedlockingjavasingletons
Double checkedlockingjavasingletonsparag
 
Node.js: Whats the Big Deal? Presented and JS Meetup Chicago
Node.js: Whats the Big Deal? Presented and JS Meetup ChicagoNode.js: Whats the Big Deal? Presented and JS Meetup Chicago
Node.js: Whats the Big Deal? Presented and JS Meetup ChicagoAziz Ali
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Edureka!
 
Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7Devang Garach
 
Java virtual machine
Java virtual machineJava virtual machine
Java virtual machineNikhil Sharma
 

Tendances (20)

JVM, byte codes & jvm languages
JVM, byte codes & jvm languagesJVM, byte codes & jvm languages
JVM, byte codes & jvm languages
 
Coroutines in Kotlin
Coroutines in KotlinCoroutines in Kotlin
Coroutines in Kotlin
 
Node.js Course 2 of 2 - Advanced techniques
Node.js Course 2 of 2 - Advanced techniquesNode.js Course 2 of 2 - Advanced techniques
Node.js Course 2 of 2 - Advanced techniques
 
Node.js Course 1 of 2 - Introduction and first steps
Node.js Course 1 of 2 - Introduction and first stepsNode.js Course 1 of 2 - Introduction and first steps
Node.js Course 1 of 2 - Introduction and first steps
 
Ola Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The JvmOla Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The Jvm
 
Java Virtual Machine
Java Virtual Machine Java Virtual Machine
Java Virtual Machine
 
Byte code jvm
Byte code jvmByte code jvm
Byte code jvm
 
Node.js an Exectutive View
Node.js an Exectutive ViewNode.js an Exectutive View
Node.js an Exectutive View
 
Java introduction with JVM architecture
Java introduction with JVM architectureJava introduction with JVM architecture
Java introduction with JVM architecture
 
JVM Bytecodes
JVM BytecodesJVM Bytecodes
JVM Bytecodes
 
Double checkedlockingjavasingletons
Double checkedlockingjavasingletonsDouble checkedlockingjavasingletons
Double checkedlockingjavasingletons
 
Node.js: Whats the Big Deal? Presented and JS Meetup Chicago
Node.js: Whats the Big Deal? Presented and JS Meetup ChicagoNode.js: Whats the Big Deal? Presented and JS Meetup Chicago
Node.js: Whats the Big Deal? Presented and JS Meetup Chicago
 
Foolangjs
FoolangjsFoolangjs
Foolangjs
 
Jvm Architecture
Jvm ArchitectureJvm Architecture
Jvm Architecture
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
 
Java-java virtual machine
Java-java virtual machineJava-java virtual machine
Java-java virtual machine
 
Nashorn
NashornNashorn
Nashorn
 
Zero mq logs
Zero mq logsZero mq logs
Zero mq logs
 
Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7
 
Java virtual machine
Java virtual machineJava virtual machine
Java virtual machine
 

Similaire à Scala e xchange 2013 haoyi li on metascala a tiny diy jvm

Java buzzwords
Java buzzwordsJava buzzwords
Java buzzwordsramesh517
 
basic core java up to operator
basic core java up to operatorbasic core java up to operator
basic core java up to operatorkamal kotecha
 
Rust Programming Language
Rust Programming LanguageRust Programming Language
Rust Programming LanguageJaeju Kim
 
DCSF19 Docker Containers & Java: What I Wish I Had Been Told
DCSF19 Docker Containers & Java: What I Wish I Had Been ToldDCSF19 Docker Containers & Java: What I Wish I Had Been Told
DCSF19 Docker Containers & Java: What I Wish I Had Been ToldDocker, Inc.
 
Performance optimization techniques for Java code
Performance optimization techniques for Java codePerformance optimization techniques for Java code
Performance optimization techniques for Java codeAttila Balazs
 
Presentation on java
Presentation on javaPresentation on java
Presentation on javawilliam john
 
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5David Voyles
 
A begineers guide of JAVA - Getting Started
 A begineers guide of JAVA - Getting Started A begineers guide of JAVA - Getting Started
A begineers guide of JAVA - Getting StartedRakesh Madugula
 
Introduction to Micronaut - JBCNConf 2019
Introduction to Micronaut - JBCNConf 2019Introduction to Micronaut - JBCNConf 2019
Introduction to Micronaut - JBCNConf 2019graemerocher
 
Virtualisation - Vagrant and Docker
Virtualisation - Vagrant and DockerVirtualisation - Vagrant and Docker
Virtualisation - Vagrant and DockerJames Ford
 
Java troubleshooting thread dump
Java troubleshooting thread dumpJava troubleshooting thread dump
Java troubleshooting thread dumpejlp12
 
A tour of Java and the JVM
A tour of Java and the JVMA tour of Java and the JVM
A tour of Java and the JVMAlex Birch
 

Similaire à Scala e xchange 2013 haoyi li on metascala a tiny diy jvm (20)

Java buzzwords
Java buzzwordsJava buzzwords
Java buzzwords
 
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptxJAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
 
basic core java up to operator
basic core java up to operatorbasic core java up to operator
basic core java up to operator
 
Rust Programming Language
Rust Programming LanguageRust Programming Language
Rust Programming Language
 
1 java introduction
1 java introduction1 java introduction
1 java introduction
 
1 java intro
1 java intro1 java intro
1 java intro
 
DCSF19 Docker Containers & Java: What I Wish I Had Been Told
DCSF19 Docker Containers & Java: What I Wish I Had Been ToldDCSF19 Docker Containers & Java: What I Wish I Had Been Told
DCSF19 Docker Containers & Java: What I Wish I Had Been Told
 
Java Basic PART I
Java Basic PART IJava Basic PART I
Java Basic PART I
 
Java programming and security
Java programming and securityJava programming and security
Java programming and security
 
Performance optimization techniques for Java code
Performance optimization techniques for Java codePerformance optimization techniques for Java code
Performance optimization techniques for Java code
 
Java lab lecture 1
Java  lab  lecture 1Java  lab  lecture 1
Java lab lecture 1
 
Presentation on java
Presentation on javaPresentation on java
Presentation on java
 
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
 
java Features
java Featuresjava Features
java Features
 
A begineers guide of JAVA - Getting Started
 A begineers guide of JAVA - Getting Started A begineers guide of JAVA - Getting Started
A begineers guide of JAVA - Getting Started
 
Introduction to Micronaut - JBCNConf 2019
Introduction to Micronaut - JBCNConf 2019Introduction to Micronaut - JBCNConf 2019
Introduction to Micronaut - JBCNConf 2019
 
Virtualisation - Vagrant and Docker
Virtualisation - Vagrant and DockerVirtualisation - Vagrant and Docker
Virtualisation - Vagrant and Docker
 
JAVA for Every one
JAVA for Every oneJAVA for Every one
JAVA for Every one
 
Java troubleshooting thread dump
Java troubleshooting thread dumpJava troubleshooting thread dump
Java troubleshooting thread dump
 
A tour of Java and the JVM
A tour of Java and the JVMA tour of Java and the JVM
A tour of Java and the JVM
 

Plus de Skills Matter

5 things cucumber is bad at by Richard Lawrence
5 things cucumber is bad at by Richard Lawrence5 things cucumber is bad at by Richard Lawrence
5 things cucumber is bad at by Richard LawrenceSkills Matter
 
Patterns for slick database applications
Patterns for slick database applicationsPatterns for slick database applications
Patterns for slick database applicationsSkills Matter
 
Oscar reiken jr on our success at manheim
Oscar reiken jr on our success at manheimOscar reiken jr on our success at manheim
Oscar reiken jr on our success at manheimSkills Matter
 
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...Skills Matter
 
Cukeup nyc ian dees on elixir, erlang, and cucumberl
Cukeup nyc ian dees on elixir, erlang, and cucumberlCukeup nyc ian dees on elixir, erlang, and cucumberl
Cukeup nyc ian dees on elixir, erlang, and cucumberlSkills Matter
 
Cukeup nyc peter bell on getting started with cucumber.js
Cukeup nyc peter bell on getting started with cucumber.jsCukeup nyc peter bell on getting started with cucumber.js
Cukeup nyc peter bell on getting started with cucumber.jsSkills Matter
 
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...Skills Matter
 
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...Skills Matter
 
Progressive f# tutorials nyc don syme on keynote f# in the open source world
Progressive f# tutorials nyc don syme on keynote f# in the open source worldProgressive f# tutorials nyc don syme on keynote f# in the open source world
Progressive f# tutorials nyc don syme on keynote f# in the open source worldSkills Matter
 
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...Skills Matter
 
Dmitry mozorov on code quotations code as-data for f#
Dmitry mozorov on code quotations code as-data for f#Dmitry mozorov on code quotations code as-data for f#
Dmitry mozorov on code quotations code as-data for f#Skills Matter
 
A poet's guide_to_acceptance_testing
A poet's guide_to_acceptance_testingA poet's guide_to_acceptance_testing
A poet's guide_to_acceptance_testingSkills Matter
 
Russ miles-cloudfoundry-deep-dive
Russ miles-cloudfoundry-deep-diveRuss miles-cloudfoundry-deep-dive
Russ miles-cloudfoundry-deep-diveSkills Matter
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSkills Matter
 
I went to_a_communications_workshop_and_they_t
I went to_a_communications_workshop_and_they_tI went to_a_communications_workshop_and_they_t
I went to_a_communications_workshop_and_they_tSkills Matter
 

Plus de Skills Matter (20)

5 things cucumber is bad at by Richard Lawrence
5 things cucumber is bad at by Richard Lawrence5 things cucumber is bad at by Richard Lawrence
5 things cucumber is bad at by Richard Lawrence
 
Patterns for slick database applications
Patterns for slick database applicationsPatterns for slick database applications
Patterns for slick database applications
 
Oscar reiken jr on our success at manheim
Oscar reiken jr on our success at manheimOscar reiken jr on our success at manheim
Oscar reiken jr on our success at manheim
 
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
 
Cukeup nyc ian dees on elixir, erlang, and cucumberl
Cukeup nyc ian dees on elixir, erlang, and cucumberlCukeup nyc ian dees on elixir, erlang, and cucumberl
Cukeup nyc ian dees on elixir, erlang, and cucumberl
 
Cukeup nyc peter bell on getting started with cucumber.js
Cukeup nyc peter bell on getting started with cucumber.jsCukeup nyc peter bell on getting started with cucumber.js
Cukeup nyc peter bell on getting started with cucumber.js
 
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...
 
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
 
Progressive f# tutorials nyc don syme on keynote f# in the open source world
Progressive f# tutorials nyc don syme on keynote f# in the open source worldProgressive f# tutorials nyc don syme on keynote f# in the open source world
Progressive f# tutorials nyc don syme on keynote f# in the open source world
 
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...
 
Dmitry mozorov on code quotations code as-data for f#
Dmitry mozorov on code quotations code as-data for f#Dmitry mozorov on code quotations code as-data for f#
Dmitry mozorov on code quotations code as-data for f#
 
A poet's guide_to_acceptance_testing
A poet's guide_to_acceptance_testingA poet's guide_to_acceptance_testing
A poet's guide_to_acceptance_testing
 
Russ miles-cloudfoundry-deep-dive
Russ miles-cloudfoundry-deep-diveRuss miles-cloudfoundry-deep-dive
Russ miles-cloudfoundry-deep-dive
 
Serendipity-neo4j
Serendipity-neo4jSerendipity-neo4j
Serendipity-neo4j
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelism
 
Plug 20110217
Plug   20110217Plug   20110217
Plug 20110217
 
Lug presentation
Lug presentationLug presentation
Lug presentation
 
I went to_a_communications_workshop_and_they_t
I went to_a_communications_workshop_and_they_tI went to_a_communications_workshop_and_they_t
I went to_a_communications_workshop_and_they_t
 
Plug saiku
Plug   saikuPlug   saiku
Plug saiku
 
Huguk lily
Huguk lilyHuguk lily
Huguk lily
 

Dernier

The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 

Dernier (20)

The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 

Scala e xchange 2013 haoyi li on metascala a tiny diy jvm

  • 1. Metascala A tiny DIY JVM https://github.com/lihaoyi/Metascala Li Haoyi haoyi@dropbox.com Scala Exchange 2nd Dec 2013
  • 2. Who am I? Li Haoyi Write Python during the day Write Scala at night
  • 3. What is Metascala? ● A JVM ● in 3000 lines of Scala ● Which can load & interpret java programs ● And can interpret itself!
  • 4. Size comparison ● Metascala: ~3,000 lines ● Avian JVM: ~80,000 lines ● OpenJDK: ~1,000,000 lines
  • 5. Basic Usage Create a new metascala VM Plain Old Java Object Captured variables are serialized into VM’s environment Closure’s class file is given to VM to load/parse/execute Result is extracted from VM into host environment No global state Any other classes necessary to evaluate the closure are loaded from the current Classpath
  • 6. It’s Metacircular! Need to give the outer VM more than the 1mb default heap VM inside a VM! Simpler program avoids initializing the scala/java std libraries, which takes forever under double-interpretation. Takes a while (~10s) to produce result
  • 8. Performance Comparison ● OpenJDK: 1.0x ● Metascala: ~100x ● Meta-Metascala: ~10000x
  • 9. Why Metascala? ● Fun to explore the innards of the JVM ● An almost-fully secure Java runtime! ● Small size makes fiddling fun
  • 10. Why Metascala? ● Fun to explore the innards of the JVM ● An almost-fully secure Java runtime! ● Small size makes fiddling fun
  • 11. Quick Tour Immutable Defs: ~380 loc Native Bindings: ~650 loc Bytecode SSA transform: ~650 loc Runtime data structures: 820 loc Binary heap & Copying GC: 132 loc DIY scala-pickling: 132 loc “This is a VM”: 243 loc
  • 12. Quick Tour: Tests Tests for basic Java features GC Fuzz-tests Test Metacircularity! Scala std lib usage
  • 13. What’s a Heap? Fig 1. A Heap
  • 14. What’s a Garbage Collector? Blit (copy) all roots to new heap Stop when you’ve scanned everything Not pseudocode Scan the already copied things for more things and copy them too
  • 15. Why Metascala? ● Fun to explore the innards of the JVM ● An almost-fully secure Java runtime! ● Small size makes fiddling fun
  • 17. And Limited Memory! Not an OOM Error! We throw this ourselves
  • 18. Explicitly defined capabilities Every external call has to be explicitly defined and enabled
  • 19. Security Characteristics ● ● ● ● Finite instruction count Finite memory Well-defined interface to outside world Doesn’t rely on Java Security Model at all! ● Still some holes…
  • 20. Security Holes ● ● ● ● ● Classloader can read from anywhere Time spent classloading not accounted Memory spent on classes not accounted GC time not accounted “native” methods’ time/memory not accounted
  • 21. Basic Problem Outside World User code resource consumption is bounded VM’s runtime resource usage can be made to grow arbitrarily large Classes Native method calls User Code Runtime Data Structures Garbage Collector
  • 22. Possible Solution Put a VM Inside a VM! Works, ... but 10000x slowdown Outside World Fixed Unaccounted Costs Outside World Classes Native method calls User Code Runtime Data Structures Garbage Collector
  • 23. Another Possible Solution Move more components into virtual runtime Difficult to bootstrap correctly WIP Outside World Native method calls Classes Garbage Collector User Code Runtime Data Structures
  • 24. Why Metascala? ● Fun to explore the innards of the JVM ● An almost-fully secure Java runtime! ● Small size makes fiddling fun
  • 26. Ugliness ● Long compile times ● Nasty JVM Interface ● Impossible Debugging
  • 27. Long compile times ● ● 100 lines/s ● Twice as slow (50 lines/s) on my older machine!
  • 28. Nasty JVM Interface Ideal World Initialized User Code Real World Linear Initialization Std Library Initialized User Code Std Library Clean Interfaces VM VM LazyInitialization means repeated dives back into lib/native code Nasty Language VM Interface
  • 29. Java’s dirty little secret The Verbosity of Java with the Safety of C WTF! I’d never use these things!
  • 30. You probably do What happens if you don’t have them Almost every Java program ever uses these things.
  • 31. Next Steps ● Maximize correctness ○ Implement Threads & IO ○ Fix bugs (GC, native calls, etc.) ● Solidify security characteristics ○ Still plenty of unaccounted-for memory/processing ○ Some can be hosted “within” VM itself ● Simplify Std-Lib/VM interface ○ Try using Android Std Lib?
  • 32. Possible Experiments ● Native codegen instead of an interpreter? ○ Generate/exec native code through JNI ○ Heap is already a binary blob that can be easily passed to native code ● Bytecode transforms and optimizations? ○ Already in SSA form ● Continuations, Isolates, Value Classes? ● Port the whole thing to Scala.Js?
  • 33. Metascala: a tiny DIY JVM Ask me about: ● Single Static Assignment form ● Copying Garbage Collection ● sun.misc.Unsafe ● Warts of the .class file format ● Capabilities-based security ● Abandoned approaches