~ubuntu-branches/ubuntu/vivid/nqp/vivid-proposed

« back to all changes in this revision

Viewing changes to src/vm/jvm/runtime/org/perl6/nqp/sixmodel/SerializationContext.java

  • Committer: Package Import Robot
  • Author(s): Alessandro Ghedini
  • Date: 2013-11-01 12:09:18 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20131101120918-kx51sl0sxl3exsxi
Tags: 2013.10-1
* New upstream release
* Bump versioned (Build-)Depends on parrot
* Update patches
* Install new README.pod
* Fix vcs-field-not-canonical
* Do not install rubyish examples
* Do not Depends on parrot-devel anymore
* Add 07_disable-serialization-tests.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.perl6.nqp.sixmodel;
 
2
 
 
3
import java.util.ArrayList;
 
4
import java.util.HashMap;
 
5
 
 
6
import org.perl6.nqp.runtime.CodeRef;
 
7
 
 
8
/**
 
9
 * A serialization context holds a list of objects and code references that live
 
10
 * within a serialization boundary.
 
11
 */
 
12
public class SerializationContext {
 
13
    /* The handle of this SC. */
 
14
    public String handle;
 
15
    
 
16
    /* Description (probably the file name) if any. */
 
17
    public String description;
 
18
    
 
19
    /* The root set of objects that live in this SC. */
 
20
    public ArrayList<SixModelObject> root_objects;
 
21
    
 
22
    /* The root set of STables that live in this SC. */
 
23
    public ArrayList<STable> root_stables;
 
24
    
 
25
    /* The root set of code refs that live in this SC. */
 
26
    public ArrayList<CodeRef> root_codes;
 
27
    
 
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;
 
33
    
 
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;
 
40
    
 
41
    public SerializationContext(String handle) {
 
42
        this.handle = 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>();
 
49
    }
 
50
    
 
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");
 
57
        
 
58
        /* Add to root set. */
 
59
        int newSlot = root_objects.size();
 
60
        root_objects.add(obj);
 
61
        
 
62
        /* Add repossession entry. */
 
63
        rep_indexes.add(newSlot << 1);
 
64
        rep_scs.add(origSC);
 
65
    }
 
66
    
 
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();
 
72
        root_stables.add(st);
 
73
        
 
74
        /* Add repossession entry. */
 
75
        rep_indexes.add((newSlot << 1) | 1);
 
76
        rep_scs.add(origSC);
 
77
    }
 
78
}