1
package org.perl6.nqp.sixmodel;
3
import java.util.ArrayList;
4
import java.util.HashMap;
6
import org.perl6.nqp.runtime.CodeRef;
9
* A serialization context holds a list of objects and code references that live
10
* within a serialization boundary.
12
public class SerializationContext {
13
/* The handle of this SC. */
16
/* Description (probably the file name) if any. */
17
public String description;
19
/* The root set of objects that live in this SC. */
20
public ArrayList<SixModelObject> root_objects;
22
/* The root set of STables that live in this SC. */
23
public ArrayList<STable> root_stables;
25
/* The root set of code refs that live in this SC. */
26
public ArrayList<CodeRef> root_codes;
28
/* Repossession info. The following lists have matching indexes, each
29
* representing the integer of an object in our root set along with the SC
30
* that the object was originally from. */
31
public ArrayList<Integer> rep_indexes;
32
public ArrayList<SerializationContext> rep_scs;
34
/* Some things we deserialize are not directly in an SC, root set, but
35
* rather are owned by others. This is mostly thanks to Parrot legacy,
36
* where not everything was a 6model object. This maps such owned
37
* objects to their owner. It is used to determine what object should
38
* be repossessed in the case a write barrier is hit. */
39
public HashMap<SixModelObject, SixModelObject> owned_objects;
41
public SerializationContext(String handle) {
43
this.root_objects = new ArrayList<SixModelObject>();
44
this.root_stables = new ArrayList<STable>();
45
this.root_codes = new ArrayList<CodeRef>();
46
this.rep_indexes = new ArrayList<Integer>();
47
this.rep_scs = new ArrayList<SerializationContext>();
48
this.owned_objects = new HashMap<SixModelObject, SixModelObject>();
51
/* Takes an object and adds it to this SC's root set, and installs a
52
* reposession entry. */
53
public void repossessObject(SerializationContext origSC, SixModelObject obj) {
54
/* Check the object really lives in the SC root set. */
55
if (obj.sc.root_objects.indexOf(obj) < 0)
56
throw new RuntimeException("Attempt to repossess object not in this context");
58
/* Add to root set. */
59
int newSlot = root_objects.size();
60
root_objects.add(obj);
62
/* Add repossession entry. */
63
rep_indexes.add(newSlot << 1);
67
/* Takes an STable and adds it to this SC's root set, and installs a
68
* reposession entry. */
69
public void repossessSTable(SerializationContext origSC, STable st) {
70
/* Add to root set. */
71
int newSlot = root_stables.size();
74
/* Add repossession entry. */
75
rep_indexes.add((newSlot << 1) | 1);