1 / 40

Understanding Serialization in Programming Systems

Explore the concept of serialization, its uses in storing, transferring, and compiling data. Learn about data graphs, abstract storage, pickling, and implementation in various languages like Java and Alice.

Download Presentation

Understanding Serialization in Programming Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Serialisierung Benedict Fehringer Proseminar Programmiersysteme Betreuer: Guido Tack

  2. Übersicht • Einführung • Datengraphen und abstrakter Speicher • Pickles (Unpickling, Pickling) • Bsp. in Java und Alice

  3. Einführung

  4. Was meint Serialisierung? Serialisierung bedeutet, dass ein Datengraph in eine eindimensionale (lineare)-Form gebracht wird, so dass diese eindeutig in den Ursprungs-Datengraph umgewandelt werden kann.

  5. Wozu benötigt man Serialisierung? • Speichern • Transferieren • Compilieren

  6. Umsetzung der Serialisierung in verschiedenen Sprachen • CLU (eine Sprache, die von Pascal abstammt); (B. Liskov and St. Zilles, 1974) • JAVA (Roger Riggs, Jim Waldo, Ann Wollrath Sun Microsystems, Inc., 1996), Microsoft`s.NET Framework • Ruby oder Python • SML/NJ (A. W. Appel and D. B. MacQueen, 1994), OCaml, Alice • Mozart/Oz

  7. Datengraphen und abstrakter Speicher

  8. Bsp. für einen Datengraph class A { public string s; public int i; public B b; } class B { public int j; public A a; } A x = new A (); B y = new B (); x.s = „aaa“; x.i = 24; x.b = y; y.j = 45; y.a = x;

  9. Bsp. für einen Datengraph object x Adresse Label Inhalt 0 1 2 3 4 object x int string object y int 1 | 2 | 3 „24“ „aaa“ 0 | 4 „45“ string „aaa“ object y int „24“ int „45“

  10. Datengraph (formal) Ein Datengraph ist eine endliche Funktion g, so dass gilt: Ran(g)  Lab x (Str  Dom(g)*)

  11. Abstrakter Speicher • Spezielle Datenstrukturen benötigen eine spezielle Repräsentation (Zahlen, Strings, Arrays,...) (kann zur Optimierung implementiert werden)

  12. Pickles

  13. Definitionen Pickle: - linear - external - „Platform-unabhängige“ Pickling - Umwandlung eines Datengraphen in einen Pickle Unpickling - Umkehrvorgang zum Pickling

  14. Konstruktion/Unpickling von Datengraphen • Baum • azyklischer Graph • zyklischer Graph

  15. Baum Instruktion # Nachfolger a c 0 c b c 0 d 0 c d b 2 a 2

  16. Baum Instruktion # Nachfolger a c 0 c b c 0 d 0 c d b 2 a 2

  17. Azyklischer Graph Instruktion # Nachfolger a c 0 b STORE 0 - LOAD 0 - c d d 0 b 2 a 2

  18. Azyklischer Graph Instruktion # Nachfolger a c 0 b STORE 0 - LOAD 0 - c d d 0 b 2 a 2

  19. Zyklischer Graph Instruktion # Nachfolger a PROMISE 0 a 2 c 1 b STORE 1 - LOAD 1 - c d d 0 b 2 FULFIL 0 2

  20. Zyklischer Graph Instruktion # Nachfolger a PROMISE 0 a 2 c 1 b STORE 1 - LOAD 1 - c d d 0 b 2 FULFIL 0 2

  21. Pickling • Schritt 1: Datengraph Pickle-Baum • Schritt 2: Pickle-Baum Postorder-Linearisierung • Schritt 3: Postorder-Linearisierung Pickle

  22. Schritt 1 0: a a 1: c b b c d d -> 1 -> 0 Datengraph Pickle-Baum

  23. Knoten # Nachfolger -> 0 - 1:c 1 -> 1 - d 0 b 2 2 0:a Schritt 2 0: a b 1: c -> 0 d -> 1 Pickle-Baum Postorder-Linearisierung

  24. Knoten Knoten # Nachfolger # Nachfolger -> 0 1:c -> 1 d b 0:a - 1 - 0 2 2 PROMISE 0 a c STORE 1 LOAD 1 d b FULFIL 0 2 1 - - 0 2 2 Schritt 3 Postorder-Linearisierung Bottom-up-Pickle

  25. Top-Down-Pickles • Präorder statt Postorder Top-Down Pickle • Kein Promise/Fulfill nötig

  26. Verschiedene Darstellungen eines Pickle-Bäume 0: a 0: a 1: c b b = -> 1 d d 1: c -> 0 -> 1 -> 0

  27. Implementier-Details • Depth First Search (Graph Pickle-Baum Pickle) • Bestimmung der maximalen Stack-Höhe

  28. Realisierung in JAVA und Alice

  29. JAVA-Objekt-Modell • Klassen • Objekte • Felder • Methoden • ...

  30. Pickling in Java • Objekte können serialisiert werden • Top-Down-Mechanismus • Pruning

  31. Bsp. für Pickling in Java import java.io.Serializable;public class A implements Serializable{public int i;public string s; }

  32. Bsp. für Pickling in Java 10 public class FlattenA20 {30 public static void main(String [] args)40 {50 A a = new A();60 FileOutputStream fos = new FileOutputStream(“aa.ser");70 ObjectOutputStream out = new ObjectOutputStream(fos);80 out.writeObject(a);90 out.close();100 }110 }

  33. Bsp. für Pickling in Java 10 public class InflateA20 {30 public static void main(String [] args)40 {50 A a = null;60 FileInputStream fis = null;70 ObjectInputStream in = null;80 try90 {100 fis = new FileInputStream(“aa.ser");110 in = new ObjectInputStream(fis);120 a = (A)in.readObject();130 in.close();140 }150 catch(IOException ex) { ERROR!!!}160 catch(ClassNotFoundException ex) { ERROR!!! } 170 } 180 }

  34. Pruning • der Programmierer kann selbst entscheiden, welcher Teil gepickelt werden soll und welcher nicht. • Die nicht zu Pickelndeln Teile müssen markiert werden

  35. Bsp. für Pickling in Java import java.io.Serializable;public class A implements Serializable{transient public int i;public string s; }

  36. Pickling in Alice • Pickling beliebiger Daten • Typsicherheit • Anwendung: z.B. Komponentensystem / Compiler

  37. Bsp. für Pickling in Alice signature NUM = sig type t fun fromInt : int -> t fun toInt : t -> int fun add : t * t -> t end structure Num :> NUM = struct type t = int fun toInt n = n fun fromInt n = n val add = op+ end

  38. Bsp. für Pickling in Alice Pickling: Pickle.save: string * package -> unit Pickle.save ("Num." ^ Pickle.extension, pack Num :> NUM) Unpickling: Pickle.load: string -> package structure Num' = unpack Pickle.load ("Num." ^ Pickle.extension) : NUM

  39. Bsp. für Pickling in Alice Achtung! Num'.add (Num.fromInt 4, Num.fromInt 5) 1.0-1.39: argument type mismatch: t * t does not match argument type Num'.t * Num'.t because type Num.t does not unify with Num'.t

  40. Literaturverzeichnis • Guido Tack, Linearisation, Minimisation and Transformation of Data Graphs with Transients. Diplomarbeit, Saarbrücken, Mai 2003 • Roger Riggs, Jim Waldo, Ann Wollrath Sun Microsystems, Inc., Pickling State in the Java™ System, Toronto, Ontario, Canada, June 1996 • Java Object Serialization Specification. Available from http://java.sun.com/j2se/1.4/docs/guide/serialization/, 2001. • The Alice Project. Available from http://www.ps.uni-sb.de/alice, 2003. Homepage at the Programming Systems Lab, Universität des Saarlandes, Saarbrücken.

More Related