smalltalk on the jvm
DESCRIPTION
ESUG 2011, EdinburghTRANSCRIPT
![Page 1: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/1.jpg)
Smalltalk on the JVM By James Ladd [email protected] http://redline.st @redline_st - ESUG 2011
![Page 2: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/2.jpg)
![Page 3: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/3.jpg)
JVM Implementation Challenges
![Page 4: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/4.jpg)
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)
![Page 5: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/5.jpg)
JVM Implementation Challenges:
JVM Unit of execution is a class
Load Class newInstance() <init> called
![Page 6: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/6.jpg)
JVM Implementation Challenges:
JVM loads classes with a Class Loader
loadClass("java.lang.String")
![Page 7: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/7.jpg)
JVM Implementation Challenges:
JVM loads classes with a Class Loader
SmalltalkClassLoader loadClass('Object') = Object.st
![Page 8: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/8.jpg)
JVM Implementation Challenges:
JVM classes are namespaced
java.lang, st.redline Package Must specify fully qualified name
![Page 9: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/9.jpg)
JVM Implementation Challenges:
Calling methods is cumbersome
Very static Must specify exact type
![Page 10: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/10.jpg)
JVM Implementation Challenges:
Calling methods is cumbersome St/redline/ProtoObject (Ljava/lang/Object;)Ljava/lang/StringBuilder;
![Page 11: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/11.jpg)
JVM Implementation Challenges:
Calling methods is cumbersome
Luckily everything in Smalltalk is an Object (ProtoObject)
![Page 12: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/12.jpg)
JVM Implementation Challenges:
Methods are part of a class
Change class to change method
![Page 13: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/13.jpg)
Redline Smalltalk Internals
![Page 14: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/14.jpg)
Redline Smalltalk Internals
Uses ANTLR
Smalltalk.g PreProc.g
![Page 15: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/15.jpg)
Redline Smalltalk Internals
Users ANTLR
Jim Idle wrote pre-processor Will eventually make grammar skinnable
![Page 16: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/16.jpg)
Redline Smalltalk Internals
Uses ObjectWeb ASM
Bytecode class writing library
![Page 17: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/17.jpg)
Redline Smalltalk Internals
Base of hierarchy is ProtoObject
Java object that implements primitives Each primitive is a static Java method
![Page 18: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/18.jpg)
Redline Smalltalk Internals
Base of hierarchy is ProtoObject
Smalltalk Objects built using message sends to ProtoObject Compiler's job is to generate message sends
![Page 19: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/19.jpg)
Redline Smalltalk Internals
Two other Java Objects
ProtoMethod ProtoBlock
![Page 20: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/20.jpg)
Redline Smalltalk Internals
Redline Java Class Loader
SmalltalkClassLoader Searches for source (.st file)
![Page 21: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/21.jpg)
Redline Smalltalk Internals
Redline Java Class Loader
Can use Smalltalk classes from Java
![Page 22: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/22.jpg)
Redline Smalltalk Internals
Namespace support
Modelled on Java Packages File path is package
![Page 23: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/23.jpg)
Redline Smalltalk Internals
Namespace support
st/redline/Object = st/redline package Each class has own 'set' of imports
![Page 24: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/24.jpg)
Redline Smalltalk Internals
SmalltalkClassLoader
Partitions applications within single JVM
![Page 25: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/25.jpg)
Redline Execution
![Page 26: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/26.jpg)
Redline Execution
What happens when st.redline.Example is Executed?
![Page 27: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/27.jpg)
Redline Execution: executing st.redline.Example
Invoke class from command line ./stic st.redline.Example
![Page 28: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/28.jpg)
Redline Execution: executing st.redline.Example
Stic Creates instance of SmalltalkClassLoader Sets as context ClassLoader
![Page 29: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/29.jpg)
Redline Execution: executing st.redline.Example
Stic Asks SmalltalkClassLoader to bootstrap Asks ProtoObject to resolve 'st.redline.Example'
![Page 30: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/30.jpg)
Redline Execution: executing st.redline.Example
ProtoObject loads class Class.forName(“st.redline.Example”);
![Page 31: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/31.jpg)
Redline Execution: executing st.redline.Example
SmalltalkClassLoader Checks cache – returns object if present Searches source path for 'Example.st' ie: src/main/smalltalk/st/redline/Example.st
![Page 32: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/32.jpg)
Redline Execution: executing st.redline.Example
SmalltalkClassLoader Invokes compiler on source file Resulting class loaded into JVM Instance created class.newInstance()
![Page 33: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/33.jpg)
Redline Execution: executing st.redline.Example
Method newInstance()
Runs Class <init> method <init> method contains message sends from Source
![Page 34: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/34.jpg)
Redline Execution: executing st.redline.Example
Compiler
Creates Java class to contain logic Class is subclass of ProtoObject Package is based on file path
![Page 35: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/35.jpg)
Redline Execution: executing st.redline.Example
Compiler
Creates <init> method, which is executed when instance created. Logic in 'st.redline.Example' is encoded as message sends: ProtoObject.primitiveSend(...)
![Page 36: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/36.jpg)
Redline Execution: executing st.redline.Example
Compiler – Smalltalk Methods
Methods are encoded as a message send to compile the method source. Because class doesn't exist yet.
![Page 37: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/37.jpg)
Redline Execution: executing st.redline.Example
Method Compilation
Methods are 1st class objects Subclass of ProtoMethod Added to receivers method dictionary
![Page 38: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/38.jpg)
Redline Execution: executing st.redline.Example
Method Compilation
All Methods Objects have only 1 method applyTo(...) Contains logic embodied in Smalltalk method
![Page 39: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/39.jpg)
Redline Execution: executing st.redline.Example
Block Compilation
Blocks are 1st class objects Subclass of ProtoBlock
![Page 40: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/40.jpg)
Redline Execution: executing st.redline.Example
Block Compilation
Blocks instance created when used Have a Java applyTo(...) method ^ semantics handled correctly
![Page 41: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/41.jpg)
Redline Demo
![Page 42: Smalltalk on the JVM](https://reader034.vdocuments.us/reader034/viewer/2022051616/55388df24a7959016b8b4805/html5/thumbnails/42.jpg)
Questions? Please visit: http://redline.st