100 likes | 127 Views
This presentation by Nicholas Cameron at Imperial College London in 2006 discusses the concepts of implicit and explicit state management in Java programming. Implicit state is shown to be error-prone, non-intuitive and lacks abstraction, while explicit state offers better clarity and separation of concerns. The talk covers practical examples, case studies, and the implementation of a StateJ class to demonstrate the benefits of using explicit state management in concurrent programming. Ongoing work focuses on enhancing the StateJ compiler and exploring further case studies to improve concurrent program writing.
E N D
A state abstraction for Java Ferruccio Damiani, Paola Giannini, Sophia Drossopoulou, Nick Cameron, Elena Giachino Presentation by Nick Cameron ncameron@doc.ic.ac.uk Imperial College London
Implicit state Object a Object a m m m() Some internal change time Nicholas Cameron DoC Imperial College 2006
{ while (…) { try { this.wait(); } catch (…) {…} } … } { … this.notifyAll(); } Implicit state • Hard to program • Non-intuitive • Lack of abstraction • Error prone • Missed statements • Boilerplate • Mixes functionality with coordination code Nicholas Cameron DoC Imperial College 2006
Explicit state Object a Object a s1 s1 m1() m1 m1 s2 s2 m2() m2 m2 as2 time Nicholas Cameron DoC Imperial College 2006
StateJ class C { String f1; state s1 { void m1() {…} } state s2 { void m1() {…} void m2() {…} } void m3() {…} } Nicholas Cameron DoC Imperial College 2006
StateJ { this!!s2; this!!previous; } state s2 { void m() as s1 } Nicholas Cameron DoC Imperial College 2006
Case studies Java, StateJ, Chords Buffer reader/writer lock Latch Santa Claus problem Submarine Radar problem … Class Buffer { state full { void put(Object o) as partial } state empty { Object get() as partial } state partial { void put (Object o) {…} Object get() {…} } } Programming with StateJ Nicholas Cameron DoC Imperial College 2006
Implementation and Formal System • Formal system extends Featherweight Java • Multiple threads • States, state change statement, spawn statement • Type sound • Implementation - compiler • Compiles (large) subset of Java + states to Java • Inheritance Nicholas Cameron DoC Imperial College 2006
Current work • States can have fields state s1 (int n) {…} this!!s1(x); • Effect system to ensure fields are not accessed outside the correct state • Improving the StateJ compiler • Further case studies Nicholas Cameron DoC Imperial College 2006
Conclusion • Explicit states makes it easier to write concurrent programs. • Objects have state, method dispatch depends on current state. • Type safe formal system and compiler. • Ongoing work… Nicholas Cameron DoC Imperial College 2006