SlideShare ist ein Scribd-Unternehmen logo
1 von 69
@drkrab

Erjang — a JVM-based Erlang VM
 A Journey into Erlang Land




                                 Eugène Delacroix, Hamlet and Horatio in the Graveyard
Kresten Krab Thorup
Trifork CTO
Java was designed
 in the client-server age
Synchronous
  coordination
     prevailed
Erlang’s raison d’être


      Build reliable systems
      in the presence of errors
         Isolation + Concurrency
process modeling




                     996
                      A1
                   JAV
                CE
               SIN
process
                  modeling



object-oriented
   modeling
Photo:Vlado Bennett
Anthropomorphic Programming


    Secretary



    Manager              Courier              Manager



    Worker




                Morven Gentleman, SP&E 1981; Thomas & Barry, JOT 2004.
Hierachical Organizations

                   Supervisor



           Supervisor        Supervisor



  Worker            Worker           Worker
client            actor
     message
               Guard/     behavior
               Queue

                               state
client            actor
     message
               Guard/     behavior
               Queue

                               state
client               actor
     message
                 Guard/      behavior
                 Queue

                                  state
           shared
         immutable
           values
box




 empty




 full(X)
box




             empty

{‘put’,X}


             full(X)
box




             empty

{‘put’,X}              {‘take’,From} /
                       send(From, X)

             full(X)
box() ➞ empty().

empty() ➞                        box
 receive
  {‘put’, X} ➞
      full(X)
 end.                             empty

full(X) ➞            {‘put’,X}              {‘take’,From} /
                                            send(From, X)
 receive
  {‘take’, From} ➞                full(X)
      From ! X,
      empty()
 end.
box() ➞ empty().

empty() ➞                        box
 receive
  {‘put’, X} ➞
      full(X)
 end.                             empty

full(X) ➞            {‘put’,X}              {‘take’,From} /
                                            send(From, X)
 receive
  {‘take’, From} ➞                full(X)
      From ! X,
      empty()
 end.                                     {‘peek’,From} /
                                        send(From,{‘ok’, X})
box() ➞ empty().

empty() ➞                             box
 receive
  {‘put’, X} ➞
      full(X)
 end.                                  empty

full(X) ➞                 {‘put’,X}              {‘take’,From} /
                                                 send(From, X)
 receive
  {‘take’, From} ➞                     full(X)
      From ! X,
      empty();
  {‘peek’, From} ➞                             {‘peek’,From} /
                                             send(From,{‘ok’, X})
      From ! {‘ok’, X},
      full(X)
 end.
box() ➞ empty().

empty() ➞
 receive
  {‘put’, X} ➞
      full(X)
 end.

full(X) ➞
 receive
  {‘take’, From} ➞
      From ! X,
      empty();
  {‘peek’, From} ➞
      From ! {‘ok’, X},
      full(X)
 end.
box() ➞ empty().
                          Box = spawn(box),
empty() ➞
 receive
  {‘put’, X} ➞
      full(X)
 end.

full(X) ➞
 receive
  {‘take’, From} ➞
      From ! X,
      empty();
  {‘peek’, From} ➞
      From ! {‘ok’, X},
      full(X)
 end.
box() ➞ empty().
                          Box = spawn(box),
empty() ➞
 receive                  Box ! {‘put’, 27},
  {‘put’, X} ➞
      full(X)
 end.

full(X) ➞
 receive
  {‘take’, From} ➞
      From ! X,
      empty();
  {‘peek’, From} ➞
      From ! {‘ok’, X},
      full(X)
 end.
box() ➞ empty().
                          Box = spawn(box),
empty() ➞
 receive                  Box ! {‘put’, 27},
  {‘put’, X} ➞
      full(X)             Box ! {‘take’, self()},
 end.                     receive
                           Value ➞ print(Value)
full(X) ➞                 end
 receive
  {‘take’, From} ➞
      From ! X,
      empty();
  {‘peek’, From} ➞
      From ! {‘ok’, X},
      full(X)
 end.
box() ➞ empty().

empty() ➞
 receive
  {‘put’, X} ➞
      full(X)
 end.

full(X) ➞
 receive
  {‘take’, From} ➞
      From ! X,
      empty();
  {‘peek’, From} ➞
      From ! {‘ok’, X},
      full(X)
 end.
box() ➞ empty().
                          Box = spawn(box),
empty() ➞
 receive
  {‘put’, X} ➞
      full(X)
 end.

full(X) ➞
 receive
  {‘take’, From} ➞
      From ! X,
      empty();
  {‘peek’, From} ➞
      From ! {‘ok’, X},
      full(X)
 end.
box() ➞ empty().
                          Box = spawn(box),
empty() ➞
 receive                  Box ! {‘put’, 27},
  {‘put’, X} ➞
      full(X)
 end.

full(X) ➞
 receive
  {‘take’, From} ➞
      From ! X,
      empty();
  {‘peek’, From} ➞
      From ! {‘ok’, X},
      full(X)
 end.
box() ➞ empty().
                          Box = spawn(box),
empty() ➞
 receive                  Box ! {‘put’, 27},
  {‘put’, X} ➞
      full(X)             Box ! {‘take’, self()},
 end.                     receive
                           Value ➞ print(Value)
full(X) ➞                 end
 receive
  {‘take’, From} ➞
      From ! X,
      empty();
  {‘peek’, From} ➞
      From ! {‘ok’, X},
      full(X)
 end.
Your Erlang Program
        OTP Framework
BEAM




  BEAM Emulator            BIFs
        Your favorite OS
Your Erlang Program
        OTP Framework
BEAM




  BEAM Emulator            BIFs



        Your favorite OS
Your Erlang Program
        OTP Framework
BEAM




       ERJANG              BIFs
JVM




       Java Virtual Machine
        Your favorite OS
Runtime Compiler


  BEAM Reader        foo.beam



  Type Analysis



  JVM Codegen     foo-2a149ada.jar
Runtime Compiler


  BEAM Reader        foo.beam



  Type Analysis



  JVM Codegen     foo-2a149ada.jar
Runtime Compiler                                                    *
      erlang:load_module          error_handler:undefined_function




  BEAM Reader                                foo.beam



  Type Analysis            ClassLoader.loadClass(“erjang.m.foo”)




  JVM Codegen                            foo-2a149ada.jar
Runtime Compiler                                                    *
      erlang:load_module          error_handler:undefined_function




  BEAM Reader                                foo.beam



  Type Analysis            ClassLoader.loadClass(“erjang.m.foo”)




  JVM Codegen                            foo-2a149ada.jar
Language Concepts
      Erlang           Erjang
     Process +       Coroutine +
     Messaging      Mailbox [Kilim]

                      Trampoline
      Tail Calls
                       Encoding

        State        Immutable /
    Encapsulation   Persistent Data
Tail Calls
-module(bar).
bat([H | T], T2) ->
 bat(T, foo(H, T2));
bat([], T2) -> T2.

foo(H, T) ->
  lists:reverse(H ++ T).
Tail Calls
-module(bar).
bat([H | T], T2) ->
 bat(T, foo(H, T2));
bat([], T2) -> T2.

foo(H, T) ->
  lists:reverse(H ++ T).
The BEAM Code
{function, bat, {nargs,2}}.
{label,264}.
  {test,is_nonempty_list,{else,265},[{x,0}]}.
  {get_list,{x,0},{x,0},{y,0}}.
  {call,2,foo}.
  {move,{x,0},{x,1}}.
  {move,{y,0},{x,0}}.
  {call_last,2,bat,1}.
{label,265}.
  {test,is_nil,{else,263},[{x,0}]}.
  {move,{x,1},{x,0}}.
  return.
{label,263}.
  {func_info,{atom,appmon_bar},{atom,bat},2}.
public static EObject
    bat___2(EProc eproc, EObject arg1, EObject arg2)
{
   ECons cons; ENil nil;
   tail:
     if((cons = arg1.test_nonempty_list()) != null) {
         // extract list
         EObject hd = cons.head();
         EObject tl = cons.tail();
         // call foo/2
         EObject tmp = foo___2(eproc, hd, arg2);
         // self-tail recursion
         arg1 = tl;
         arg2 = tmp;
         goto tail;
      } else if ((nil = arg1.test_nil()) != null) {
         return arg2;
      }
    throw ERT.Bodyc_info(am_bar, am_bat, 2);
}
Erlang               JVM
-module(bar).
bat([H | T], T2) ->
 bat(T, foo(H, T2));
bat([], T2) -> T2.

foo(H, T) ->
  lists:reverse(H ++ T).
Erlang               JVM
-module(bar).
bat([H | T], T2) ->
 bat(T, foo(H, T2));
bat([], T2) -> T2.

foo(H, T) ->
  lists:reverse(H ++ T).
foo(H, T) ->
                     lists:reverse(H ++ T).


public static EObject
    foo__2(EProc p, EObject H, EObject T)
{
    EObject r = foo__2$body(p,H,T);
    while (r == TAIL_MARKER) {
       r = p.tail.go();
    }
    return r;
}
foo(H, T) ->
                            lists:reverse(H ++ T).


public static
    EObject foo__2$body(EProc p, EObject H, EObject T)
{
    // Tmp = erlang:’++’(H,T)
    EObject tmp = erlang_append__2.invoke(p,H,T);

    // return lists:reverse(Tmp)
    p.tail = lists__reverse_1;
    p.arg1 = tmp;
    return TAIL_MARKER;
}
The ring!
“The world is concurrent. ... I could not drive
my car on the highway if I did not intuitively
understand the notion of concurrency...”       —Joe Armstrong




                                                            http://www.youtube.com/watch?v=NXLuyZMEZbk
“The world is concurrent. ... I could not drive
my car on the highway if I did not intuitively
understand the notion of concurrency...”       —Joe Armstrong




                                                            http://www.youtube.com/watch?v=NXLuyZMEZbk
@drkrab

Weitere ähnliche Inhalte

Was ist angesagt?

Operator Overloading In Scala
Operator Overloading In ScalaOperator Overloading In Scala
Operator Overloading In ScalaJoey Gibson
 
Denis Lebedev, Swift
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, SwiftYandex
 
Object Equality in Scala
Object Equality in ScalaObject Equality in Scala
Object Equality in ScalaKnoldus Inc.
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meetMario Fusco
 
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDBTDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDBtdc-globalcode
 
Expression trees in c#, Алексей Голубь (Svitla Systems)
Expression trees in c#, Алексей Голубь (Svitla Systems)Expression trees in c#, Алексей Голубь (Svitla Systems)
Expression trees in c#, Алексей Голубь (Svitla Systems)Alina Vilk
 
TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...
TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...
TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...tdc-globalcode
 
Expression trees in c#
Expression trees in c#Expression trees in c#
Expression trees in c#Oleksii Holub
 
Kotlin from-scratch 2 - functions
Kotlin from-scratch 2 - functionsKotlin from-scratch 2 - functions
Kotlin from-scratch 2 - functionsFranco Lombardo
 
Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7Paulo Morgado
 
Beauty and Power of Go
Beauty and Power of GoBeauty and Power of Go
Beauty and Power of GoFrank Müller
 
About java
About javaAbout java
About javaJay Xu
 
3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в Java3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в JavaDEVTYPE
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlinintelliyole
 
The Ring programming language version 1.5.4 book - Part 35 of 185
The Ring programming language version 1.5.4 book - Part 35 of 185The Ring programming language version 1.5.4 book - Part 35 of 185
The Ring programming language version 1.5.4 book - Part 35 of 185Mahmoud Samir Fayed
 
Kotlin, 어떻게 동작하나요
Kotlin, 어떻게 동작하나요Kotlin, 어떻게 동작하나요
Kotlin, 어떻게 동작하나요Chang W. Doh
 

Was ist angesagt? (20)

Operator Overloading In Scala
Operator Overloading In ScalaOperator Overloading In Scala
Operator Overloading In Scala
 
Denis Lebedev, Swift
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, Swift
 
Object Equality in Scala
Object Equality in ScalaObject Equality in Scala
Object Equality in Scala
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
 
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDBTDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
 
Expression trees in c#, Алексей Голубь (Svitla Systems)
Expression trees in c#, Алексей Голубь (Svitla Systems)Expression trees in c#, Алексей Голубь (Svitla Systems)
Expression trees in c#, Алексей Голубь (Svitla Systems)
 
TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...
TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...
TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...
 
Go Java, Go!
Go Java, Go!Go Java, Go!
Go Java, Go!
 
Expression trees in c#
Expression trees in c#Expression trees in c#
Expression trees in c#
 
Kotlin from-scratch 2 - functions
Kotlin from-scratch 2 - functionsKotlin from-scratch 2 - functions
Kotlin from-scratch 2 - functions
 
Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7
 
Beauty and Power of Go
Beauty and Power of GoBeauty and Power of Go
Beauty and Power of Go
 
About java
About javaAbout java
About java
 
Swift Introduction
Swift IntroductionSwift Introduction
Swift Introduction
 
3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в Java3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в Java
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlin
 
The Ring programming language version 1.5.4 book - Part 35 of 185
The Ring programming language version 1.5.4 book - Part 35 of 185The Ring programming language version 1.5.4 book - Part 35 of 185
The Ring programming language version 1.5.4 book - Part 35 of 185
 
Go Java, Go!
Go Java, Go!Go Java, Go!
Go Java, Go!
 
Go Java, Go!
Go Java, Go!Go Java, Go!
Go Java, Go!
 
Kotlin, 어떻게 동작하나요
Kotlin, 어떻게 동작하나요Kotlin, 어떻게 동작하나요
Kotlin, 어떻게 동작하나요
 

Andere mochten auch

Strade dipinte
Strade dipinteStrade dipinte
Strade dipintemarsetti
 
Album 1 1976 1984
Album 1 1976 1984Album 1 1976 1984
Album 1 1976 1984marsetti
 
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]Kresten Krab Thorup
 
Ins Avis N4
Ins Avis N4Ins Avis N4
Ins Avis N4marsetti
 
Ins Avis N9
Ins Avis N9Ins Avis N9
Ins Avis N9marsetti
 
Storia_shay
Storia_shayStoria_shay
Storia_shaymarsetti
 
Album 5 2006 2007
Album 5 2006   2007Album 5 2006   2007
Album 5 2006 2007marsetti
 
Ins Avis N1
Ins Avis N1Ins Avis N1
Ins Avis N1marsetti
 

Andere mochten auch (9)

Strade dipinte
Strade dipinteStrade dipinte
Strade dipinte
 
Album 1 1976 1984
Album 1 1976 1984Album 1 1976 1984
Album 1 1976 1984
 
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
 
Ins Avis N4
Ins Avis N4Ins Avis N4
Ins Avis N4
 
Ruby on the JVM
Ruby on the JVMRuby on the JVM
Ruby on the JVM
 
Ins Avis N9
Ins Avis N9Ins Avis N9
Ins Avis N9
 
Storia_shay
Storia_shayStoria_shay
Storia_shay
 
Album 5 2006 2007
Album 5 2006   2007Album 5 2006   2007
Album 5 2006 2007
 
Ins Avis N1
Ins Avis N1Ins Avis N1
Ins Avis N1
 

Ähnlich wie Erjang - A JVM-based Erlang VM

No excuses, switch to kotlin
No excuses, switch to kotlinNo excuses, switch to kotlin
No excuses, switch to kotlinThijs Suijten
 
Concurrent Application Development using Scala
Concurrent Application Development using ScalaConcurrent Application Development using Scala
Concurrent Application Development using ScalaSiarhiej Siemianchuk
 
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfModify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfarjuncorner565
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my dayTor Ivry
 
ECMAScript 6 and beyond
ECMAScript 6 and beyondECMAScript 6 and beyond
ECMAScript 6 and beyondFrancis Johny
 
C++ QUICK REFERENCE.pdf
C++ QUICK REFERENCE.pdfC++ QUICK REFERENCE.pdf
C++ QUICK REFERENCE.pdffqerwqdfad
 
CppQuickRef.pdf
CppQuickRef.pdfCppQuickRef.pdf
CppQuickRef.pdfkurimaru1
 
The java language cheat sheet
The java language cheat sheetThe java language cheat sheet
The java language cheat sheetanand_study
 
Java Question help needed In the program Fill the Add statements.pdf
Java Question  help needed In the program Fill the Add statements.pdfJava Question  help needed In the program Fill the Add statements.pdf
Java Question help needed In the program Fill the Add statements.pdfkamdinrossihoungma74
 
Fp in scala part 2
Fp in scala part 2Fp in scala part 2
Fp in scala part 2Hang Zhao
 
C++ Quick Reference Sheet from Hoomanb.com
C++ Quick Reference Sheet from Hoomanb.comC++ Quick Reference Sheet from Hoomanb.com
C++ Quick Reference Sheet from Hoomanb.comFrescatiStory
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?Adam Dudczak
 
An Intro To ES6
An Intro To ES6An Intro To ES6
An Intro To ES6FITC
 
Go: It's Not Just For Google
Go: It's Not Just For GoogleGo: It's Not Just For Google
Go: It's Not Just For GoogleEleanor McHugh
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 

Ähnlich wie Erjang - A JVM-based Erlang VM (20)

Introduction kot iin
Introduction kot iinIntroduction kot iin
Introduction kot iin
 
Swift Study #7
Swift Study #7Swift Study #7
Swift Study #7
 
No excuses, switch to kotlin
No excuses, switch to kotlinNo excuses, switch to kotlin
No excuses, switch to kotlin
 
Concurrent Application Development using Scala
Concurrent Application Development using ScalaConcurrent Application Development using Scala
Concurrent Application Development using Scala
 
groovy & grails - lecture 3
groovy & grails - lecture 3groovy & grails - lecture 3
groovy & grails - lecture 3
 
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfModify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my day
 
ECMAScript 6 and beyond
ECMAScript 6 and beyondECMAScript 6 and beyond
ECMAScript 6 and beyond
 
C++ QUICK REFERENCE.pdf
C++ QUICK REFERENCE.pdfC++ QUICK REFERENCE.pdf
C++ QUICK REFERENCE.pdf
 
CppQuickRef.pdf
CppQuickRef.pdfCppQuickRef.pdf
CppQuickRef.pdf
 
The java language cheat sheet
The java language cheat sheetThe java language cheat sheet
The java language cheat sheet
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
Rust-lang
Rust-langRust-lang
Rust-lang
 
Java Question help needed In the program Fill the Add statements.pdf
Java Question  help needed In the program Fill the Add statements.pdfJava Question  help needed In the program Fill the Add statements.pdf
Java Question help needed In the program Fill the Add statements.pdf
 
Fp in scala part 2
Fp in scala part 2Fp in scala part 2
Fp in scala part 2
 
C++ Quick Reference Sheet from Hoomanb.com
C++ Quick Reference Sheet from Hoomanb.comC++ Quick Reference Sheet from Hoomanb.com
C++ Quick Reference Sheet from Hoomanb.com
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?
 
An Intro To ES6
An Intro To ES6An Intro To ES6
An Intro To ES6
 
Go: It's Not Just For Google
Go: It's Not Just For GoogleGo: It's Not Just For Google
Go: It's Not Just For Google
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6
 

Kürzlich hochgeladen

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Kürzlich hochgeladen (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

Erjang - A JVM-based Erlang VM

  • 1. @drkrab Erjang — a JVM-based Erlang VM A Journey into Erlang Land Eugène Delacroix, Hamlet and Horatio in the Graveyard Kresten Krab Thorup Trifork CTO
  • 2. Java was designed in the client-server age
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10. Erlang’s raison d’être Build reliable systems in the presence of errors Isolation + Concurrency
  • 11. process modeling 996 A1 JAV CE SIN
  • 12. process modeling object-oriented modeling
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25. Anthropomorphic Programming Secretary Manager Courier Manager Worker Morven Gentleman, SP&E 1981; Thomas & Barry, JOT 2004.
  • 26. Hierachical Organizations Supervisor Supervisor Supervisor Worker Worker Worker
  • 27. client actor message Guard/ behavior Queue state
  • 28. client actor message Guard/ behavior Queue state
  • 29. client actor message Guard/ behavior Queue state shared immutable values
  • 31. box empty {‘put’,X} full(X)
  • 32. box empty {‘put’,X} {‘take’,From} / send(From, X) full(X)
  • 33. box() ➞ empty(). empty() ➞ box receive {‘put’, X} ➞ full(X) end. empty full(X) ➞ {‘put’,X} {‘take’,From} / send(From, X) receive {‘take’, From} ➞ full(X) From ! X, empty() end.
  • 34. box() ➞ empty(). empty() ➞ box receive {‘put’, X} ➞ full(X) end. empty full(X) ➞ {‘put’,X} {‘take’,From} / send(From, X) receive {‘take’, From} ➞ full(X) From ! X, empty() end. {‘peek’,From} / send(From,{‘ok’, X})
  • 35. box() ➞ empty(). empty() ➞ box receive {‘put’, X} ➞ full(X) end. empty full(X) ➞ {‘put’,X} {‘take’,From} / send(From, X) receive {‘take’, From} ➞ full(X) From ! X, empty(); {‘peek’, From} ➞ {‘peek’,From} / send(From,{‘ok’, X}) From ! {‘ok’, X}, full(X) end.
  • 36. box() ➞ empty(). empty() ➞ receive {‘put’, X} ➞ full(X) end. full(X) ➞ receive {‘take’, From} ➞ From ! X, empty(); {‘peek’, From} ➞ From ! {‘ok’, X}, full(X) end.
  • 37. box() ➞ empty(). Box = spawn(box), empty() ➞ receive {‘put’, X} ➞ full(X) end. full(X) ➞ receive {‘take’, From} ➞ From ! X, empty(); {‘peek’, From} ➞ From ! {‘ok’, X}, full(X) end.
  • 38. box() ➞ empty(). Box = spawn(box), empty() ➞ receive Box ! {‘put’, 27}, {‘put’, X} ➞ full(X) end. full(X) ➞ receive {‘take’, From} ➞ From ! X, empty(); {‘peek’, From} ➞ From ! {‘ok’, X}, full(X) end.
  • 39. box() ➞ empty(). Box = spawn(box), empty() ➞ receive Box ! {‘put’, 27}, {‘put’, X} ➞ full(X) Box ! {‘take’, self()}, end. receive Value ➞ print(Value) full(X) ➞ end receive {‘take’, From} ➞ From ! X, empty(); {‘peek’, From} ➞ From ! {‘ok’, X}, full(X) end.
  • 40. box() ➞ empty(). empty() ➞ receive {‘put’, X} ➞ full(X) end. full(X) ➞ receive {‘take’, From} ➞ From ! X, empty(); {‘peek’, From} ➞ From ! {‘ok’, X}, full(X) end.
  • 41. box() ➞ empty(). Box = spawn(box), empty() ➞ receive {‘put’, X} ➞ full(X) end. full(X) ➞ receive {‘take’, From} ➞ From ! X, empty(); {‘peek’, From} ➞ From ! {‘ok’, X}, full(X) end.
  • 42. box() ➞ empty(). Box = spawn(box), empty() ➞ receive Box ! {‘put’, 27}, {‘put’, X} ➞ full(X) end. full(X) ➞ receive {‘take’, From} ➞ From ! X, empty(); {‘peek’, From} ➞ From ! {‘ok’, X}, full(X) end.
  • 43. box() ➞ empty(). Box = spawn(box), empty() ➞ receive Box ! {‘put’, 27}, {‘put’, X} ➞ full(X) Box ! {‘take’, self()}, end. receive Value ➞ print(Value) full(X) ➞ end receive {‘take’, From} ➞ From ! X, empty(); {‘peek’, From} ➞ From ! {‘ok’, X}, full(X) end.
  • 44.
  • 45. Your Erlang Program OTP Framework BEAM BEAM Emulator BIFs Your favorite OS
  • 46. Your Erlang Program OTP Framework BEAM BEAM Emulator BIFs Your favorite OS
  • 47. Your Erlang Program OTP Framework BEAM ERJANG BIFs JVM Java Virtual Machine Your favorite OS
  • 48. Runtime Compiler BEAM Reader foo.beam Type Analysis JVM Codegen foo-2a149ada.jar
  • 49. Runtime Compiler BEAM Reader foo.beam Type Analysis JVM Codegen foo-2a149ada.jar
  • 50. Runtime Compiler * erlang:load_module error_handler:undefined_function BEAM Reader foo.beam Type Analysis ClassLoader.loadClass(“erjang.m.foo”) JVM Codegen foo-2a149ada.jar
  • 51. Runtime Compiler * erlang:load_module error_handler:undefined_function BEAM Reader foo.beam Type Analysis ClassLoader.loadClass(“erjang.m.foo”) JVM Codegen foo-2a149ada.jar
  • 52. Language Concepts Erlang Erjang Process + Coroutine + Messaging Mailbox [Kilim] Trampoline Tail Calls Encoding State Immutable / Encapsulation Persistent Data
  • 53. Tail Calls -module(bar). bat([H | T], T2) -> bat(T, foo(H, T2)); bat([], T2) -> T2. foo(H, T) -> lists:reverse(H ++ T).
  • 54. Tail Calls -module(bar). bat([H | T], T2) -> bat(T, foo(H, T2)); bat([], T2) -> T2. foo(H, T) -> lists:reverse(H ++ T).
  • 55. The BEAM Code {function, bat, {nargs,2}}. {label,264}. {test,is_nonempty_list,{else,265},[{x,0}]}. {get_list,{x,0},{x,0},{y,0}}. {call,2,foo}. {move,{x,0},{x,1}}. {move,{y,0},{x,0}}. {call_last,2,bat,1}. {label,265}. {test,is_nil,{else,263},[{x,0}]}. {move,{x,1},{x,0}}. return. {label,263}. {func_info,{atom,appmon_bar},{atom,bat},2}.
  • 56. public static EObject bat___2(EProc eproc, EObject arg1, EObject arg2) { ECons cons; ENil nil; tail: if((cons = arg1.test_nonempty_list()) != null) { // extract list EObject hd = cons.head(); EObject tl = cons.tail(); // call foo/2 EObject tmp = foo___2(eproc, hd, arg2); // self-tail recursion arg1 = tl; arg2 = tmp; goto tail; } else if ((nil = arg1.test_nil()) != null) { return arg2; } throw ERT.Bodyc_info(am_bar, am_bat, 2); }
  • 57. Erlang JVM -module(bar). bat([H | T], T2) -> bat(T, foo(H, T2)); bat([], T2) -> T2. foo(H, T) -> lists:reverse(H ++ T).
  • 58. Erlang JVM -module(bar). bat([H | T], T2) -> bat(T, foo(H, T2)); bat([], T2) -> T2. foo(H, T) -> lists:reverse(H ++ T).
  • 59. foo(H, T) -> lists:reverse(H ++ T). public static EObject foo__2(EProc p, EObject H, EObject T) { EObject r = foo__2$body(p,H,T); while (r == TAIL_MARKER) { r = p.tail.go(); } return r; }
  • 60. foo(H, T) -> lists:reverse(H ++ T). public static EObject foo__2$body(EProc p, EObject H, EObject T) { // Tmp = erlang:’++’(H,T) EObject tmp = erlang_append__2.invoke(p,H,T); // return lists:reverse(Tmp) p.tail = lists__reverse_1; p.arg1 = tmp; return TAIL_MARKER; }
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67. “The world is concurrent. ... I could not drive my car on the highway if I did not intuitively understand the notion of concurrency...” —Joe Armstrong http://www.youtube.com/watch?v=NXLuyZMEZbk
  • 68. “The world is concurrent. ... I could not drive my car on the highway if I did not intuitively understand the notion of concurrency...” —Joe Armstrong http://www.youtube.com/watch?v=NXLuyZMEZbk

Hinweis der Redaktion