RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics...

32
Roos Instruments, Inc. Roos Instruments, Inc. RTALK - RTALK - SMALLTALK ON THE SMALLTALK ON THE JVM JVM

Transcript of RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics...

Page 1: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

Roos Instruments, Inc.Roos Instruments, Inc.

RTALK - RTALK - SMALLTALK ON THESMALLTALK ON THEJVMJVM

Page 2: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

Roos Instruments, Inc.Roos Instruments, Inc.

HARDWARE AND SOFTWAREHARDWARE AND SOFTWAREFOR IC TESTFOR IC TEST

Page 3: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

Smalltalk BasicsSmalltalk Basics

Message Based

Everything is an Object

Simple syntax

Fast

ODA ( On Demand Assembler )

Excellent FFI

Supports extreme agile programming

Page 4: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

Smalltalk Code ExampleSmalltalk Code Example

testHanoiMove: numberOfDisks from: source to: dest temp: temp "<modified:sys=GAKRE8CA,time=06/28/11 at 04:39:33 pm> " numberOfDisks == 1 ifTrue: [^self]. self testHanoiMove: numberOfDisks - 1 from: source to: temp temp: dest; testHanoiMove: numberOfDisks - 1 from: temp to: dest temp: source

Page 5: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

SMALLTALK AT RI SMALLTALK AT RI

Since 1989

Efficiency - 3 to 9x Java

Low errors - 1/3 Java

500K lines of code vs 2.5M

But we now have Obsolete Platforms

OS/2

Digitalk

Heisenbug

Page 6: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

Porting optionsPorting options

Another Smalltalk

Same end game

Another language

Will have to test 2.5M lines of code

Port at the VM level

Difficult until JSR 292

Page 7: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

Existing ArchitectureExisting Architecture

VM + OBJECT MEMORY

UI

FFI

APPLICATIONCODE

OS/2

PRIMITIVES

FILES

COMPILER

NETWORK

METHODS

Page 8: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

ProcessProcess

Analyze Existing code usage

Build Tools

Byte Code inspectors

Reverse compilers

Define a translation interface

Port as is ( don't try to improve it)

Convert Op sys calls to async messages

Page 9: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

New ArchitectureNew Architecture

VM + OBJECT MEMORY

UIBrowser

FFI?

APPLICATIONCODE

Java

PRIMITIVES

FILESGuru

COMPILER

NETWORKProxies

METHODS

Async socket Protocol

PBC

RIRI

Page 10: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

Architecture MismatchesArchitecture Mismatches

Stack + 2 registers ( eax edx)

Stack space == variable space

Object Memory ( ints stored in pointer )

Type artifacts

Page 11: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

Stack Var StructureStack Var Structure

var1...

edx

eax

self

args

var array

edx

eax

self

args

self

args

var1...

Normal Stack

Remote Context

Block Stack

Page 12: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

Object StructureObject Structure

Shape + flags

SIZE

METHOD ARRAY

POINTER

PRIMITIVE long, double

byte[], double[], RtObject[], Object

ri.RtObject

[[methods][methods][]...]

Page 13: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

Methods from ST to JavaMethods from ST to Java

Use supplied ST compiler

Translate to PBC

constants serialization

byte code conversion

fixup dead code, order

Translate from PBC to Java Class

Use ASM

Build GWT inline cache on demand

Page 14: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

JVM ArchitectureJVM Architecture

JAVA CLASS

APPLICATIONCODE

PRIMITIVES

SMALLTALK COMPILER

METHODS

PBC TRANSLATE

JAVA TRANSLATE

CONSTANTS

JAVA AS OP SYS

OBJECT MEMORY

Page 15: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

Portable Code ExamplePortable Code Example:CODE,type=classMethod,class=RtDictionary,selector=initialSize,args=0,vars=0,blocks=0,pbc=04000000230124022301240240023438240223021E initialSize "Private - Answer the initial number of elements that a new instance of IdentityDictionary contains." ^8

Page 16: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

Method StructureMethod Structure

PBC File

JavaClassFile

Method Handle

class

selector

source

flags

pragmas

Page 17: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

ByteCode Differences ByteCode Differences

25 PBC but only 4 real differences

Method Invocation

Primitives

Blocks and returns

Constants

Page 18: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

GWT as inline cacheGWT as inline cache

GWT

LOOKUPSET TARGET

GWT

COLLECT INSERT SPREAD INVOKE

Fallback

Match

Airity fix Callsite

Page 19: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

GWTGWT

STACK

MATCH PATH

TESTINSERTDROP

NEXT GWT

selfargs... Compare toAirity Fix Extract ==

True

False

Page 20: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

BlocksBlocks

Code plus context

Code is just another method

Replaced stack vars with shared array

Non local return

returns to caller of creator

use var array to locate return frame

throw exceptio

Page 21: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

Block Code ExampleBlock Code ExamplehandleMessage:aMessage "<modified:sys=GAKRE8CA,time=04/26/11 at 07:55:14 am> " "Message is an RtSystemMessage" | dst hdlrs parameters channel| parameters := aMessage parameters. dst := aMessage destination. channel := (parameters at:1) asUpperCase. (dst isNil or:[dst = '00000000']) ifTrue:[" broadcasts look up by channel " " but drop if I am waiting for the response " hdlrs := handlers riDetectAll:[ :h | h key = channel]. hdlrs isEmpty ifTrue:[ Object allSubclasses do:[:c | c monitorsTopic:channel message:aMessage]]. dst := ''. handlers do:[ :a | a key = channel ifTrue:[(a value at:2) handleSystemMessage:aMessage]] ] ifFalse:[ " private so lookup by topic " handlers do:[ :a | a key = channel ifTrue:[(a value at:2) handleSystemMessage:aMessage]]].

Page 22: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

Return Code ExampleReturn Code Exampleincludes: anObject "Answer true if the receiver contains an element equal to anObject, else answer false." self do: [ :element | anObject = element ifTrue: [^true]]. ^false

Page 23: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

Stack Var StructureStack Var Structure

var1...

edx

eax

self

args

var array

edx

eax

self

args

self

args

var1...

Normal Stack

Remote Context

Block Stack

Page 24: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

PrimitivesPrimitives

Along with bytecodes do all the work

Written in Java with RtObject args

Supports fallback to Smalltalk code

Low level ( math ) and high level (string)

Largest Java Code effort ( 1500 lines )

Page 25: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

Primitive Code ExamplePrimitive Code Example

at: anInteger "Answer the object in the receiver at index position anInteger. If the receiver does not have indexed instance variables, or if anInteger is greater than the number of indexed instance variables, report an error." <primitive: 60> ^self primitiveFailed

// prim 45 static public RtObject primFLoatExp(RtObject rcvr) { // return exponential of the receiver double c=rcvr.getDoubleValue(); return new RtObject(Math.exp(c)); }

Page 26: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

Constants/LiteralsConstants/Literals

In Smalltalk can be any object

In Java are limited to primitives

In reality are also limited in ST

primitives and arrays of primitives

Globals and Class Vars (use prim)

Use Constant Methodhandle to create

name is serialized constant

Page 27: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

Callsite managementCallsite management

Need to invalidate on code changes

Current approach is to drop all

Also drop at 30K sites

Page 28: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

FUTURE TOPICSFUTURE TOPICS

Coroutines

Debugger

FFI

Performance

Page 29: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

FFI Code ExampleFFI Code ExampleallocSharedMem: pBaseAddress name: pszName size: ulSize flags: ulFlags <api: '#300' struct ulong ulong ulong ulong> ^self invalidArgument

Page 30: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

DebuggerDebugger

Stack var inspection

Hop step jump

instances inspection

Currently using JVMTI

slow

requires C code agent

Page 31: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

Hanoi Code ExampleHanoi Code Example

testHanoiMove: numberOfDisks from: source to: dest temp: temp "<modified:sys=GAKRE8CA,time=06/28/11 at 04:39:33 pm> " numberOfDisks == 1 ifTrue: [^self]. self testHanoiMove: numberOfDisks - 1 from: source to: temp temp: dest; testHanoiMove: numberOfDisks - 1 from: temp to: dest temp: source

public void testMoveLong(long numberOfDisks, long source, long dest, long temp) { if(numberOfDisks == 1L) return; testMoveLong(numberOfDisks-1L, source, temp, dest); testMoveLong(numberOfDisks-1L, temp, dest, source);}

Page 32: RTALK - SMALLTALK ON THE JVMwiki.jvmlangsummit.com/images/e/e5/Roos-Rtalk.pdfSmalltalk Basics Message Based Everything is an Object Simple syntax Fast ODA ( On Demand Assembler ) Excellent

Performance for Hanoi 20Performance for Hanoi 20

java prims 1.8 ms

smalltalk 3 ms

java boxed 4.7 ms

RtObjects 32 ms

Rtalk 65 ms