Post on 28-Sep-2020
transcript
Type-safe Communication in Java with Session Types
Raymond Hu
1
Type-safe Communication in Java with Session TypesRaymond Hu1, Nobuko Yoshida1 and Kohei Honda2
1. Imperial College London; 2. Queen Mary, Uni. of London
June 2007
Type-safe Communication in Java with Session Types
Raymond Hu
2
Overview (1)
1. Background and Related Work.2. Worked Example: Session Programming.3. Runtime Support for Session Communication.4. Conclusion and Future Work.
Overview
Type-safe Communication in Java with Session Types
Raymond Hu
3
Session Types• Type systems for process calculi:
– Takeuchi et al. An Interaction-based Language and its Typing System. (1994)– Honda et al. Language Primitives and Type Discipline for Structured Comm… (1998)– Gay and Hole. Subtyping for Session Types in the Pi Calculus. (1999)– Hole and Gay. Bounded Polymorphism in Session Types. (2003)
Theoretical Background
Type-safe Communication in Java with Session Types
Raymond Hu
4
Session Types• Type systems for process calculi:
– Takeuchi et al. An Interaction-based Language and its Typing System. (1994)– Honda et al. Language Primitives and Type Discipline for Structured Comm… (1998)– Gay and Hole. Subtyping for Session Types in the Pi Calculus. (1999)– Hole and Gay. Bounded Polymorphism in Session Types. (2003)
• Session types for object calculi:– Dezani-Ciancaglini et al. A distributed Object-oriented Language with Session... (2005)– Dezani-Ciancaglini et al. Session Types for Object-oriented Languages. (2006)– Dezani-Ciancaglini et al. Bounded Session Types for Object-oriented Languages. (2007)– Coppo et al. Asynchronous Session Types and Progress for Object-oriented... (2007)
Theoretical Background
Type-safe Communication in Java with Session Types
Raymond Hu
5
Session Types• Type systems for process calculi:
– Takeuchi et al. An Interaction-based Language and its Typing System. (1994)– Honda et al. Language Primitives and Type Discipline for Structured Comm… (1998)– Gay and Hole. Subtyping for Session Types in the Pi Calculus. (1999)– Hole and Gay. Bounded Polymorphism in Session Types. (2003)
• Session types for object calculi:– Dezani-Ciancaglini et al. A distributed Object-oriented Language with Session... (2005)– Dezani-Ciancaglini et al. Session Types for Object-oriented Languages. (2006)– Dezani-Ciancaglini et al. Bounded Session Types for Object-oriented Languages. (2007)– Coppo et al. Asynchronous Session Types and Progress for Object-oriented... (2007)
Implementation of a practical, distributed language.
Theoretical Background
Type-safe Communication in Java with Session Types
Raymond Hu
6
Implementation of Session Types• Singularity OS:
– Restricted features, not distributed.
Related Work
Type-safe Communication in Java with Session Types
Raymond Hu
7
Implementation of Session Types• Singularity OS:
– Restricted features, not distributed.• Multithreaded functional language design [VGR06]:
– Not distributed, no actual implementation.
Related Work
Type-safe Communication in Java with Session Types
Raymond Hu
8
Implementation of Session Types• Singularity OS:
– Restricted features, not distributed.• Multithreaded functional language design [VGR06]:
– Not distributed, no actual implementation.• Encodings of sess. types (e.g. Haskell [NT04], C++):
– Proof of concept, but not full implementations.
Related Work
Type-safe Communication in Java with Session Types
Raymond Hu
9
Implementation of Session Types• Singularity OS [FAHHHLL06]:
– Restricted features, not distributed.• Multithreaded functional language design [VGR06]:
– Not distributed, no actual implementation.• Encodings of sess. types (e.g. Haskell [NT04], C++):
– Proof of concept, but not full implementations.
Why use untyped sockets if we can use sessions?
Related Work
Type-safe Communication in Java with Session Types
Raymond Hu
10
Overview (2)
1. Background and Related Work.2. Worked Example: Language Design.3. Runtime Support for Session Communication.4. Conclusion and Future Work.
Overview
Type-safe Communication in Java with Session Types
Raymond Hu
11
An Online Ticket Ordering System
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
12
Protocol Specification (1)
begin
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
13
Protocol Specification (1)
begin.
!(String)
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
14
Protocol Specification (1)
begin.
!(String).?(Double)
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
15
Protocol Specification (1)
begin.
!(String).?(Double)
![
]*.…
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
16
Protocol Specification (1)
begin.?[?(String).!(Double)
]*.…
begin.
!(String).?(Double)
![
]*.…
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
17
Protocol Specification (2)
…?{
}.…
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
18
Protocol Specification (2)
…
ACCEPT: … ,
REJECT:…
?{
}.…
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
19
Protocol Specification (3)
protocol p_as {
}
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
20
Protocol Specification (3)
protocol p_as {
}
begin.!(
).end
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
21
Protocol Specification (3)
?(Address).!(Date).end
protocol p_as {
}
begin.!(
).end
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
22
Protocol Implementation (1)
protocol p_ca {begin.![!(String).?(Double)
]*.…
// CustomerSTSocket s_ca = STSocketImpl.create(p_ca);
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
23
Protocol Implementation (1)
protocol p_ca {begin.![!(String).?(Double)
]*.…
// CustomerSTSocket s_ca = STSocketImpl.create(p_ca);
s_ca.request(Agency, port);
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
24
Protocol Implementation (1)
protocol p_ca {begin.![!(String).?(Double)
]*.…
// CustomerSTSocket s_ca = STSocketImpl.create(p_ca);
s_ca.request(Agency, port);s_ca.outwhile(!decided) {
}
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
25
Protocol Implementation (1)
protocol p_ca {begin.![!(String).?(Double)
]*.…
// CustomerSTSocket s_ca = STSocketImpl.create(p_ca);
s_ca.request(Agency, port);
s_ca.send(travDetails);s_ca.outwhile(!decided) {
}
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
26
Protocol Implementation (1)
protocol p_ca {begin.![!(String).?(Double)
]*.…
// CustomerSTSocket s_ca = STSocketImpl.create(p_ca);
s_ca.request(Agency, port);
s_ca.send(travDetails);cost =
(Double)s_ca.receive();decided = …;
s_ca.outwhile(!decided) {
}
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
27
Protocol Implementation (1)
protocol p_ca {begin.![!(String).?(Double)
]*.…
// CustomerSTSocket s_ca = STSocketImpl.create(p_ca);
s_ca.request(Agency, port);
s_ca.send(travDetails);
decided = …;
s_ca.outwhile(!decided) {
}
cost = s_ca.receive();
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
28
Protocol Implementation (2)
…!{ACCEPT:
… , // 1
REJECT:… // 2
}…
// Customer
s_ca.select(ACCEPT) {… // 1
}
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
29
Protocol Implementation (2)
…!{ACCEPT:
… , // 1
REJECT:… // 2
}…
// Customer
s_ca.select(ACCEPT) {… // 1
}
if(cost < 100.00) {
}else {
}
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
30
Protocol Implementation (2)
…!{ACCEPT:
… , // 1
REJECT:… // 2
}…
// Customer
s_ca.select(ACCEPT) {… // 1
}
s_ca.select(REJECT) {… // 2
}
if(cost < 100.00) {
}else {
}
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
31
Protocol Implementation (3)
…?{ACCEPT:
… , // 1’
REJECT:… // 2’
}…
// Agency
…s_ac.branch() {
}
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
32
Protocol Implementation (3)
…?{ACCEPT:
… , // 1’
REJECT:… // 2’
}…
// Agency
case ACCEPT: {… // 1’
}case REJECT: {
… // 2’}
…s_ac.branch() {
}
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
33
Putting Customer Togetherprotocol p_ca { … }
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
34
Putting Customer Togetherprotocol p_ca { … }STSocket s_ca = STSocketImpl.create(p_ca);
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
35
Putting Customer Togetherprotocol p_ca { … }STSocket s_ca = STSocketImpl.create(p_ca);
s_ca.request(Agency, port);s_ca.outwhile(…) {
…}…
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
36
Putting Customer Togetherprotocol p_ca { … }STSocket s_ca = STSocketImpl.create(p_ca);
s_ca.request(Agency, port);s_ca.outwhile(…) {
…}…
try {
}
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
37
Putting Customer Togetherprotocol p_ca { … }STSocket s_ca = STSocketImpl.create(p_ca);
s_ca.request(Agency, port);s_ca.outwhile(…) {
…}…
catch(IOException ioe) { … }
try {
}
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
38
Putting Customer Togetherprotocol p_ca { … }STSocket s_ca = STSocketImpl.create(p_ca);
s_ca.request(Agency, port);s_ca.outwhile(…) {
…}…
catch(STIncompatibleSessionException ise) { … }catch(IOException ioe) { … }
try {
}
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
39
Putting Customer Togetherprotocol p_ca { … }STSocket s_ca = STSocketImpl.create(p_ca);
s_ca.request(Agency, port);s_ca.outwhile(…) {
…}…
catch(STIncompatibleSessionException ise) { … }catch(IOException ioe) { … }finally {
s_ca.close();}
try {
}
Worked Example: Session Programming
Type-safe Communication in Java with Session Types
Raymond Hu
40
Overview (3)
1. Background and Related Work.2. Worked Example: Language Design.3. Runtime Support for Session Communication.4. Conclusion and Future Work.
Overview
Type-safe Communication in Java with Session Types
Raymond Hu
41
Sessions over TCPMap session operations to Socket communications.– Preserve asynchrony.– Interesting case is delegation.
Runtime Support for Session Communication
Type-safe Communication in Java with Session Types
Raymond Hu
42
Sessions over TCPMap session operations to Socket communications.– Preserve asynchrony.– Interesting case is delegation.
• Possible designs:– Proxy / Integrated runtime layer.– “Lost message” forwarding (cf. Mobile IP).– “Lost message” resending.
Runtime Support for Session Communication
Type-safe Communication in Java with Session Types
Raymond Hu
43
Session Initiation
Runtime Support for Session Communication
Type-safe Communication in Java with Session Types
Raymond Hu
44
Session Initiation
1. C → A : Type of intended session.
Runtime Support for Session Communication
Type-safe Communication in Java with Session Types
Raymond Hu
45
Session Initiation
1. C → A : Type of intended session.2. A → C: “YES” if types compatible, else “NO”.
Runtime Support for Session Communication
Type-safe Communication in Java with Session Types
Raymond Hu
46
Session Communication
Runtime Support for Session Communication
Type-safe Communication in Java with Session Types
Raymond Hu
47
Session Delegation (1)
Runtime Support for Session Communication
Type-safe Communication in Java with Session Types
Raymond Hu
48
Session Delegation (2)
1. S: Create server socket on port.
Runtime Support for Session Communication
1.
Type-safe Communication in Java with Session Types
Raymond Hu
49
Session Delegation (2)
1. S: Create server socket on port.2. S → A: port
Runtime Support for Session Communication
1.← 2. port
Type-safe Communication in Java with Session Types
Raymond Hu
50
Session Delegation (2)
1. S: Create server socket on port.2. S → A: port3. A → C: IPS, port, STA(sca)
Runtime Support for Session Communication
1.← 2. port
3.
←
Type-safe Communication in Java with Session Types
Raymond Hu
51
Session Delegation (3)
4. C: Connect to IPS: port.
Runtime Support for Session Communication
Type-safe Communication in Java with Session Types
Raymond Hu
52
Session Delegation (3)
4. C: Connect to IPS: port.5. C → S: “Lost messages” according to STA(sca) - STC(sca).
Runtime Support for Session Communication
5. delivAddr
←
Type-safe Communication in Java with Session Types
Raymond Hu
53
Overview (4)
1. Background and Related Work.2. Worked Example: Language Design.3. Runtime Support for Session Communication.4. Conclusion and Future Work.
Overview
Type-safe Communication in Java with Session Types
Raymond Hu
54
Conclusionhttp://www/~rh105/sessiondj.html
Conclusion
Type-safe Communication in Java with Session Types
Raymond Hu
55
Conclusionhttp://www/~rh105/sessiondj.html
• Realised many session type principles in a concrete, practical object-oriented language.
Conclusion
Type-safe Communication in Java with Session Types
Raymond Hu
56
Conclusionhttp://www/~rh105/sessiondj.html
• Realised many session type principles in a concrete, practical object-oriented language.
• Asynchrony and distribution.
Conclusion
Type-safe Communication in Java with Session Types
Raymond Hu
57
Conclusionhttp://www/~rh105/sessiondj.html
• Realised many session type principles in a concrete, practical object-oriented language.
• Asynchrony and distribution.• Session interleaving, exceptions/failure.
Conclusion
Type-safe Communication in Java with Session Types
Raymond Hu
58
Conclusionhttp://www/~rh105/sessiondj.html
• Realised many session type principles in a concrete, practical object-oriented language.
• Asynchrony and distribution.• Session interleaving, exceptions/failure.• Protocols for session initiation, delegation and close.
Conclusion
Type-safe Communication in Java with Session Types
Raymond Hu
59
Conclusionhttp://www/~rh105/sessiondj.html
• Realised many session type principles in a concrete, practical object-oriented language.
• Asynchrony and distribution.• Session interleaving, exceptions/failure.• Protocols for session initiation, delegation and close.• Delegation protocol uses session type information.
Conclusion
Type-safe Communication in Java with Session Types
Raymond Hu
60
Future Work• Usability improvements (syntax, features, ...).• Communication optimisations.
Future Work
Type-safe Communication in Java with Session Types
Raymond Hu
61
Future Work• Usability improvements (syntax, features, ...).• Communication optimisations.• Language evaluation (large example applications).• Performance evaluation.
Future Work
Type-safe Communication in Java with Session Types
Raymond Hu
62
Future Work• Usability improvements (syntax, features, ...).• Communication optimisations.• Language evaluation (large example applications).• Performance evaluation.• Associating session types to addresses.
Future Work
Type-safe Communication in Java with Session Types
Raymond Hu
63
Future Work• Usability improvements (syntax, features, ...).• Communication optimisations.• Language evaluation (large example applications).• Performance evaluation.• Associating session types to addresses.• Class downloading and verification.
Future Work
Type-safe Communication in Java with Session Types
Raymond Hu
64
Future Work• Usability improvements (syntax, features, ...).• Communication optimisations.• Language evaluation (large example applications).• Performance evaluation.• Associating session types to addresses.• Class downloading and verification.• Session exceptions.
Future Work
Type-safe Communication in Java with Session Types
Raymond Hu
65
Future Work• Usability improvements (syntax, features, ...).• Communication optimisations.• Language evaluation (large example applications).• Performance evaluation.• Associating session types to addresses.• Class downloading and verification.• Session exceptions.• Alternative runtime designs.• Sessions over alternative transports.
Future Work
Type-safe Communication in Java with Session Types
Raymond Hu
66
Session Exceptions (Poss. Design)protocol p { begin.….end | X:….end | … }STChannel c = new STChannel(…, p);STSocket s = STSocketImpl.create(c);try {
try {s.request();…
}catch(STIncompatibleSessionException ise) { }catch(s:X) { … }catch(…) { … }
}catch(IOException ioe) { … }finally { s.close(); }
Future Work
Type-safe Communication in Java with Session Types
Raymond Hu
67
Preliminary Results (1)• For simple benchmark experiment, implemented:
begin . ![ ?( MyObject ) ]* . end
Results
Type-safe Communication in Java with Session Types
Raymond Hu
68
Preliminary Results (1)• For simple benchmark experiment, implemented:
begin . ![ ?( MyObject ) ]* . end
• Using:– STSocket and equivalent “Plain Socket”– STNIOSocket and equivalent “Plain SocketChannel”– RMI: MyObject remoteMeth(Boolean bool)
Results
Type-safe Communication in Java with Session Types
Raymond Hu
69
Preliminary Results (2)
Results
Type-safe Communication in Java with Session Types
Raymond Hu
70
Preliminary Results (3)
Results