JVM Implementation Challenges JVM Implementation Challenges: JVM - - PowerPoint PPT Presentation

jvm implementation challenges
SMART_READER_LITE
LIVE PREVIEW

JVM Implementation Challenges JVM Implementation Challenges: JVM - - PowerPoint PPT Presentation

Smalltalk on the JVM By James Ladd object@redline.st http://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 Class is not an


slide-1
SLIDE 1

Smalltalk on the JVM

By James Ladd

  • bject@redline.st

http://redline.st @redline_st

  • ESUG 2011
slide-2
SLIDE 2
slide-3
SLIDE 3

JVM Implementation Challenges

slide-4
SLIDE 4

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)

slide-5
SLIDE 5

JVM Implementation Challenges:

JVM Unit of execution is a class

Load Class newInstance() <init> called

slide-6
SLIDE 6

JVM Implementation Challenges:

JVM loads classes with a Class Loader

loadClass("java.lang.String")

slide-7
SLIDE 7

JVM Implementation Challenges:

JVM loads classes with a Class Loader

SmalltalkClassLoader loadClass('Object') = Object.st

slide-8
SLIDE 8

JVM Implementation Challenges:

JVM classes are namespaced

java.lang, st.redline Package Must specify fully qualified name

slide-9
SLIDE 9

JVM Implementation Challenges:

Calling methods is cumbersome

Very static Must specify exact type

slide-10
SLIDE 10

JVM Implementation Challenges:

Calling methods is cumbersome

St/redline/ProtoObject (Ljava/lang/Object;)Ljava/lang/StringBuilder;

slide-11
SLIDE 11

JVM Implementation Challenges:

Calling methods is cumbersome

Luckily everything in Smalltalk is an Object (ProtoObject)

slide-12
SLIDE 12

JVM Implementation Challenges:

Methods are part of a class

Change class to change method

slide-13
SLIDE 13

Redline Smalltalk Internals

slide-14
SLIDE 14

Redline Smalltalk Internals

Uses ANTLR

Smalltalk.g PreProc.g

slide-15
SLIDE 15

Redline Smalltalk Internals

Users ANTLR

Jim Idle wrote pre-processor Will eventually make grammar skinnable

slide-16
SLIDE 16

Redline Smalltalk Internals

Uses ObjectWeb ASM

Bytecode class writing library

slide-17
SLIDE 17

Redline Smalltalk Internals

Base of hierarchy is ProtoObject

Java object that implements primitives Each primitive is a static Java method

slide-18
SLIDE 18

Redline Smalltalk Internals

Base of hierarchy is ProtoObject

Smalltalk Objects built using message sends to ProtoObject Compiler's job is to generate message sends

slide-19
SLIDE 19

Redline Smalltalk Internals

Two other Java Objects

ProtoMethod ProtoBlock

slide-20
SLIDE 20

Redline Smalltalk Internals

Redline Java Class Loader

SmalltalkClassLoader Searches for source (.st file)

slide-21
SLIDE 21

Redline Smalltalk Internals

Redline Java Class Loader

Can use Smalltalk classes from Java

slide-22
SLIDE 22

Redline Smalltalk Internals

Namespace support

Modelled on Java Packages File path is package

slide-23
SLIDE 23

Redline Smalltalk Internals

Namespace support

st/redline/Object = st/redline package

Each class has own 'set' of imports

slide-24
SLIDE 24

Redline Smalltalk Internals

SmalltalkClassLoader

Partitions applications within single JVM

slide-25
SLIDE 25

Redline Execution

slide-26
SLIDE 26

Redline Execution

What happens when st.redline.Example is Executed?

slide-27
SLIDE 27

Redline Execution: executing st.redline.Example

Invoke class from command line

./stic st.redline.Example

slide-28
SLIDE 28

Redline Execution: executing st.redline.Example

Stic

Creates instance of SmalltalkClassLoader Sets as context ClassLoader

slide-29
SLIDE 29

Redline Execution: executing st.redline.Example

Stic

Asks SmalltalkClassLoader to bootstrap Asks ProtoObject to resolve 'st.redline.Example'

slide-30
SLIDE 30

Redline Execution: executing st.redline.Example

ProtoObject loads class

Class.forName(“st.redline.Example”);

slide-31
SLIDE 31

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

slide-32
SLIDE 32

Redline Execution: executing st.redline.Example

SmalltalkClassLoader

Invokes compiler on source file Resulting class loaded into JVM Instance created class.newInstance()

slide-33
SLIDE 33

Redline Execution: executing st.redline.Example

Method newInstance()

Runs Class <init> method <init> method contains message sends from Source

slide-34
SLIDE 34

Redline Execution: executing st.redline.Example

Compiler

Creates Java class to contain logic Class is subclass of ProtoObject Package is based on file path

slide-35
SLIDE 35

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(...)

slide-36
SLIDE 36

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.

slide-37
SLIDE 37

Redline Execution: executing st.redline.Example

Method Compilation

Methods are 1st class objects Subclass of ProtoMethod Added to receivers method dictionary

slide-38
SLIDE 38

Redline Execution: executing st.redline.Example

Method Compilation

All Methods Objects have only 1 method applyTo(...) Contains logic embodied in Smalltalk method

slide-39
SLIDE 39

Redline Execution: executing st.redline.Example

Block Compilation

Blocks are 1st class objects Subclass of ProtoBlock

slide-40
SLIDE 40

Redline Execution: executing st.redline.Example

Block Compilation

Blocks instance created when used Have a Java applyTo(...) method ^ semantics handled correctly

slide-41
SLIDE 41

Redline Demo

slide-42
SLIDE 42

Questions?

Please visit:

http://redline.st