next up previous
Next: Continuations Up: JiST- Java in Simulation Previous: Reflection

Tight event coupling

Encoding an event-dispatch as a method invocation has a number of additional benefits, which can significantly reduce the amount of simulation code required, as well as improve its clarity, without affecting runtime performance. These benefits are summarized in Table 3. The first benefit of this encoding is type-safety, which eliminates a common source of error: the source and target of an event are statically checked by the Java compiler. The event type information is also managed automatically at runtime, which completely eliminates the many event type constants and associated event type-cast code that is otherwise required. A third benefit is that marshalling of event parameters is performed automatically. In contrast, simulators written against event-driven libraries often require a large number of event structures and much code to simply pack and unpack parameters from these structures. Finally, debugging event-driven simulators can be onerous, because simulation events arrive at target entities from the simulation queue without context. Thus, it can be difficult to determine the cause of a faulty or unexpected incoming event. In JiST, an event can automatically carry its context information: the point of dispatch (with line numbers, if source information is available) as well as the state of the source entity. These contexts can then be chained to form an event causality trace, the equivalent of a stack trace, which may be helpful in debugging. For performance reasons, this information is collected only in JiST's debug mode.

The tight coupling of event dispatch and delivery in the form of a method invocation also has important performance implications. Tight event-loops, which can be determined only at runtime, can be dynamically optimized across the kernel-simulation boundary. The tight coupling also abstracts the simulation event queue behind simulation time semantics. This, in turn, allows the JiST runtime to execute the simulation efficiently - in parallel and optimistically - without requiring any modifications to the simulation code. Also the distribution of simulation entities across different machines can occur transparently with respect to the running simulation.


Table 3: Benefits of tight event coupling achieved through simulation time method invocations
type safety - source and target of event statically checked by compiler
event typing - not required; events automatically type-cast as they are dequeued
event structures - not required; event parameters automatically marshalled
debugging - event dispatch location and state available
execution - transparently allows for parallel, optimistic and distributed execution



next up previous
Next: Continuations Up: JiST- Java in Simulation Previous: Reflection
2006-01-18