Smalltalk on the JVMBy James Laddobject@redline.sthttp://redline.st@redline_st- ESUG 2011
JVM Implementation Challenges
JVM Implementation Challenges:JVM Unit of execution is a class              Sequence of bytes in class format             ...
JVM Implementation Challenges:JVM Unit of execution is a class                     Load Class                     newInsta...
JVM Implementation Challenges:JVM loads classes with a Class Loader       loadClass("java.lang.String")
JVM Implementation Challenges:JVM loads classes with a Class Loader       SmalltalkClassLoader       loadClass(Object) = O...
JVM Implementation Challenges:JVM classes are namespaced       java.lang, st.redline       Package       Must specify full...
JVM Implementation Challenges:Calling methods is cumbersome              Very static              Must specify exact type
JVM Implementation Challenges:Calling methods is cumbersome        St/redline/ProtoObject        (Ljava/lang/Object;)Ljava...
JVM Implementation Challenges:Calling methods is cumbersome        Luckily everything in Smalltalk is an        Object (Pr...
JVM Implementation Challenges:Methods are part of a class        Change class to change method
Redline Smalltalk Internals
Redline Smalltalk InternalsUses ANTLR         Smalltalk.g         PreProc.g
Redline Smalltalk InternalsUsers ANTLR         Jim Idle wrote pre-processor         Will eventually make grammar skinnable
Redline Smalltalk InternalsUses ObjectWeb ASM         Bytecode class writing library
Redline Smalltalk InternalsBase of hierarchy is ProtoObject         Java object that implements primitives         Each pr...
Redline Smalltalk InternalsBase of hierarchy is ProtoObject         Smalltalk Objects built using message         sends to...
Redline Smalltalk InternalsTwo other Java Objects         ProtoMethod         ProtoBlock
Redline Smalltalk InternalsRedline Java Class Loader         SmalltalkClassLoader         Searches for source (.st file)
Redline Smalltalk InternalsRedline Java Class Loader         Can use Smalltalk classes from Java
Redline Smalltalk InternalsNamespace support         Modelled on Java Packages         File path is package
Redline Smalltalk InternalsNamespace support       st/redline/Object = st/redline package       Each class has own set of ...
Redline Smalltalk InternalsSmalltalkClassLoader       Partitions applications within single JVM
Redline Execution
Redline ExecutionWhat happens when st.redline.Exampleis Executed?
Redline Execution: executing st.redline.ExampleInvoke class from command line       ./stic st.redline.Example
Redline Execution: executing st.redline.ExampleStic       Creates instance of SmalltalkClassLoader       Sets as context C...
Redline Execution: executing st.redline.ExampleStic       Asks SmalltalkClassLoader to bootstrap       Asks ProtoObject to...
Redline Execution: executing st.redline.ExampleProtoObject loads class       Class.forName(“st.redline.Example”);
Redline Execution: executing st.redline.ExampleSmalltalkClassLoader       Checks cache – returns object if present       S...
Redline Execution: executing st.redline.ExampleSmalltalkClassLoader       Invokes compiler on source file       Resulting ...
Redline Execution: executing st.redline.ExampleMethod newInstance()       Runs Class <init> method       <init> method con...
Redline Execution: executing st.redline.ExampleCompiler       Creates Java class to contain logic       Class is subclass ...
Redline Execution: executing st.redline.ExampleCompiler       Creates <init> method, which is executed when       instance...
Redline Execution: executing st.redline.ExampleCompiler – Smalltalk Methods       Methods are encoded as a message send to...
Redline Execution: executing st.redline.ExampleMethod Compilation       Methods are 1st class objects       Subclass of Pr...
Redline Execution: executing st.redline.ExampleMethod Compilation       All Methods Objects have only 1 method       apply...
Redline Execution: executing st.redline.ExampleBlock Compilation       Blocks are 1st class objects       Subclass of Prot...
Redline Execution: executing st.redline.ExampleBlock Compilation       Blocks instance created when used       Have a Java...
Redline Demo
Questions?    Please visit:    http://redline.st
Smalltalk on the JVM
Upcoming SlideShare
Loading in …5
×

Smalltalk on the JVM

1,767 views
1,657 views

Published on

ESUG 2011, Edinburgh

Published in: Technology, Education
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,767
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
18
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Smalltalk on the JVM

  1. 1. Smalltalk on the JVMBy James Laddobject@redline.sthttp://redline.st@redline_st- ESUG 2011
  2. 2. JVM Implementation Challenges
  3. 3. JVM Implementation Challenges:JVM Unit of execution is a class Sequence of bytes in class format Class is not an Object (more like data structure)
  4. 4. JVM Implementation Challenges:JVM Unit of execution is a class Load Class newInstance() <init> called
  5. 5. JVM Implementation Challenges:JVM loads classes with a Class Loader loadClass("java.lang.String")
  6. 6. JVM Implementation Challenges:JVM loads classes with a Class Loader SmalltalkClassLoader loadClass(Object) = Object.st
  7. 7. JVM Implementation Challenges:JVM classes are namespaced java.lang, st.redline Package Must specify fully qualified name
  8. 8. JVM Implementation Challenges:Calling methods is cumbersome Very static Must specify exact type
  9. 9. JVM Implementation Challenges:Calling methods is cumbersome St/redline/ProtoObject (Ljava/lang/Object;)Ljava/lang/StringBuilder;
  10. 10. JVM Implementation Challenges:Calling methods is cumbersome Luckily everything in Smalltalk is an Object (ProtoObject)
  11. 11. JVM Implementation Challenges:Methods are part of a class Change class to change method
  12. 12. Redline Smalltalk Internals
  13. 13. Redline Smalltalk InternalsUses ANTLR Smalltalk.g PreProc.g
  14. 14. Redline Smalltalk InternalsUsers ANTLR Jim Idle wrote pre-processor Will eventually make grammar skinnable
  15. 15. Redline Smalltalk InternalsUses ObjectWeb ASM Bytecode class writing library
  16. 16. Redline Smalltalk InternalsBase of hierarchy is ProtoObject Java object that implements primitives Each primitive is a static Java method
  17. 17. Redline Smalltalk InternalsBase of hierarchy is ProtoObject Smalltalk Objects built using message sends to ProtoObject Compilers job is to generate message sends
  18. 18. Redline Smalltalk InternalsTwo other Java Objects ProtoMethod ProtoBlock
  19. 19. Redline Smalltalk InternalsRedline Java Class Loader SmalltalkClassLoader Searches for source (.st file)
  20. 20. Redline Smalltalk InternalsRedline Java Class Loader Can use Smalltalk classes from Java
  21. 21. Redline Smalltalk InternalsNamespace support Modelled on Java Packages File path is package
  22. 22. Redline Smalltalk InternalsNamespace support st/redline/Object = st/redline package Each class has own set of imports
  23. 23. Redline Smalltalk InternalsSmalltalkClassLoader Partitions applications within single JVM
  24. 24. Redline Execution
  25. 25. Redline ExecutionWhat happens when st.redline.Exampleis Executed?
  26. 26. Redline Execution: executing st.redline.ExampleInvoke class from command line ./stic st.redline.Example
  27. 27. Redline Execution: executing st.redline.ExampleStic Creates instance of SmalltalkClassLoader Sets as context ClassLoader
  28. 28. Redline Execution: executing st.redline.ExampleStic Asks SmalltalkClassLoader to bootstrap Asks ProtoObject to resolve st.redline.Example
  29. 29. Redline Execution: executing st.redline.ExampleProtoObject loads class Class.forName(“st.redline.Example”);
  30. 30. Redline Execution: executing st.redline.ExampleSmalltalkClassLoader Checks cache – returns object if present Searches source path for Example.st ie: src/main/smalltalk/st/redline/Example.st
  31. 31. Redline Execution: executing st.redline.ExampleSmalltalkClassLoader Invokes compiler on source file Resulting class loaded into JVM Instance created class.newInstance()
  32. 32. Redline Execution: executing st.redline.ExampleMethod newInstance() Runs Class <init> method <init> method contains message sends from Source
  33. 33. Redline Execution: executing st.redline.ExampleCompiler Creates Java class to contain logic Class is subclass of ProtoObject Package is based on file path
  34. 34. Redline Execution: executing st.redline.ExampleCompiler Creates <init> method, which is executed when instance created. Logic in st.redline.Example is encoded as message sends: ProtoObject.primitiveSend(...)
  35. 35. Redline Execution: executing st.redline.ExampleCompiler – Smalltalk Methods Methods are encoded as a message send to compile the method source. Because class doesnt exist yet.
  36. 36. Redline Execution: executing st.redline.ExampleMethod Compilation Methods are 1st class objects Subclass of ProtoMethod Added to receivers method dictionary
  37. 37. Redline Execution: executing st.redline.ExampleMethod Compilation All Methods Objects have only 1 method applyTo(...) Contains logic embodied in Smalltalk method
  38. 38. Redline Execution: executing st.redline.ExampleBlock Compilation Blocks are 1st class objects Subclass of ProtoBlock
  39. 39. Redline Execution: executing st.redline.ExampleBlock Compilation Blocks instance created when used Have a Java applyTo(...) method ^ semantics handled correctly
  40. 40. Redline Demo
  41. 41. Questions? Please visit: http://redline.st

×