Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Stub STables and objects at deserialization start.
  • Loading branch information
jnthn committed Jan 18, 2013
1 parent 3094a4b commit 9516dc1
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/org/perl6/nqp/sixmodel/REPR.java
Expand Up @@ -78,8 +78,12 @@ public void change_type(ThreadContext tc, SixModelObject Object, SixModelObject
* serialization writer. */
// XXX void (*serialize) (ThreadContext, STable *st, void *data, SerializationWriter *writer);

/* Object deserialization. Reads the objects body in using the passed
* serialization reader. */
/* Object deserialization. Happens in two steps. The first stub step
* creates an object to be filled out later. Note that the STable may
* not be fully available yet if it's in the current compilation unit.
* The second step has the STable fully formed (though objects it
* references may not be) and should do the rest of the work. */
public abstract SixModelObject deserialize_stub(ThreadContext tc, STable st);
// XXX void (*deserialize) (ThreadContext, STable *st, void *data, SerializationReader *reader);

/**
Expand Down
64 changes: 64 additions & 0 deletions src/org/perl6/nqp/sixmodel/SerializationReader.java
Expand Up @@ -68,6 +68,15 @@ public void deserialize() {
// Split the input into the various segments.
checkAndDisectInput();
resolveDependencies();

// Handle any reposessions.
if (reposTableEntries > 0)
throw new RuntimeException("Reposession of SC objects NYI");

// Stub all of the STables and objects.
stubSTables();
stubObjects();

throw new RuntimeException("Deserialization NYI");
}

Expand Down Expand Up @@ -191,6 +200,61 @@ private void resolveDependencies() {
}
}

private void stubSTables() {
for (int i = 0; i < stTableEntries; i++) {
// Look up representation.
orig.position(stTableOffset + i * STABLES_TABLE_ENTRY_SIZE);
REPR repr = REPRRegistry.getByName(lookupString(orig.getInt()));

// Create STable stub and add it to the root STable set.
STable st = new STable(repr, null);
st.sc = sc;
sc.root_stables.add(st);
}
}

private void stubObjects() {
for (int i = 0; i < objTableEntries; i++) {
// Look up STable.
orig.position(objTableOffset + i * OBJECTS_TABLE_ENTRY_SIZE);
STable st = lookupSTable(orig.getInt(), orig.getInt());

// Now go by object flags.
SixModelObject stubObj;
orig.position(orig.position() + 4);
int flags = orig.getInt();
if (flags == 0) {
// Type object.
stubObj = new TypeObject();
stubObj.st = st;
}
else {
// Concrete object; defer to the REPR.
stubObj = st.REPR.deserialize_stub(tc, st);
}

// Place object in SC root set.
stubObj.sc = sc;
sc.root_objects.add(stubObj);
}
}


private STable lookupSTable(int scIdx, int idx) {
SerializationContext sc = locateSC(scIdx);
if (idx < 0 || idx >= sc.root_stables.size())
throw new RuntimeException("Invalid STable index (scIdx=" + scIdx + ",idx=" + idx + ")");
return sc.root_stables.get(idx);
}

private SerializationContext locateSC(int scIdx) {
if (scIdx == 0)
return sc;
if (scIdx < 1 || scIdx > dependentSCs.length)
throw new RuntimeException("Invalid dependencies table index encountered (index " + scIdx + ")");
return dependentSCs[scIdx - 1];
}

private String lookupString(int idx) {
if (idx >= sh.length)
throw new RuntimeException("Attempt to read past end of string heap (index " + idx + ")");
Expand Down
6 changes: 6 additions & 0 deletions src/org/perl6/nqp/sixmodel/reprs/KnowHOWAttribute.java
Expand Up @@ -20,4 +20,10 @@ public SixModelObject allocate(ThreadContext tc, STable st) {
obj.st = st;
return obj;
}

public SixModelObject deserialize_stub(ThreadContext tc, STable st) {
KnowHOWAttributeInstance obj = new KnowHOWAttributeInstance();
obj.st = st;
return obj;
}
}
11 changes: 11 additions & 0 deletions src/org/perl6/nqp/sixmodel/reprs/KnowHOWREPR.java
@@ -1,5 +1,8 @@
package org.perl6.nqp.sixmodel.reprs;

import java.util.ArrayList;
import java.util.HashMap;

import org.perl6.nqp.runtime.ThreadContext;
import org.perl6.nqp.sixmodel.*;

Expand All @@ -17,4 +20,12 @@ public SixModelObject allocate(ThreadContext tc, STable st) {
obj.st = st;
return obj;
}

public SixModelObject deserialize_stub(ThreadContext tc, STable st) {
KnowHOWREPRInstance obj = new KnowHOWREPRInstance();
obj.st = st;
obj.attributes = new ArrayList<SixModelObject>();
obj.methods = new HashMap<String, SixModelObject>();
return obj;
}
}
4 changes: 4 additions & 0 deletions src/org/perl6/nqp/sixmodel/reprs/P6Opaque.java
Expand Up @@ -340,4 +340,8 @@ public Class<?> findClass(String name) {
return defineClass(name, this.bytes, 0, this.bytes.length);
}
}

public SixModelObject deserialize_stub(ThreadContext tc, STable st) {
throw new RuntimeException("P6opaque deserialization NYI");
}
}
6 changes: 6 additions & 0 deletions src/org/perl6/nqp/sixmodel/reprs/P6int.java
Expand Up @@ -102,4 +102,10 @@ public void generateBoxingMethods(ThreadContext tc, STable st, ClassGen c, Const
c.addMethod(setMeth.getMethod());
setIl.dispose();
}

public SixModelObject deserialize_stub(ThreadContext tc, STable st) {
P6intInstance obj = new P6intInstance();
obj.st = st;
return obj;
}
}
6 changes: 6 additions & 0 deletions src/org/perl6/nqp/sixmodel/reprs/P6num.java
Expand Up @@ -103,4 +103,10 @@ public void generateBoxingMethods(ThreadContext tc, STable st, ClassGen c, Const
c.addMethod(setMeth.getMethod());
setIl.dispose();
}

public SixModelObject deserialize_stub(ThreadContext tc, STable st) {
P6numInstance obj = new P6numInstance();
obj.st = st;
return obj;
}
}
6 changes: 6 additions & 0 deletions src/org/perl6/nqp/sixmodel/reprs/P6str.java
Expand Up @@ -102,4 +102,10 @@ public void generateBoxingMethods(ThreadContext tc, STable st, ClassGen c, Const
c.addMethod(setMeth.getMethod());
setIl.dispose();
}

public SixModelObject deserialize_stub(ThreadContext tc, STable st) {
P6strInstance obj = new P6strInstance();
obj.st = st;
return obj;
}
}
4 changes: 4 additions & 0 deletions src/org/perl6/nqp/sixmodel/reprs/SCRef.java
Expand Up @@ -20,4 +20,8 @@ public SixModelObject allocate(ThreadContext tc, STable st) {
obj.st = st;
return obj;
}

public SixModelObject deserialize_stub(ThreadContext tc, STable st) {
throw new RuntimeException("SCRef does not participate in serialization");
}
}
4 changes: 4 additions & 0 deletions src/org/perl6/nqp/sixmodel/reprs/Uninstantiable.java
Expand Up @@ -18,4 +18,8 @@ public SixModelObject type_object_for(ThreadContext tc, SixModelObject HOW) {
public SixModelObject allocate(ThreadContext tc, STable st) {
throw new RuntimeException("You cannot create an instance of this type");
}

public SixModelObject deserialize_stub(ThreadContext tc, STable st) {
throw new RuntimeException("Cannot stub an Uninstantiable instance");
}
}
6 changes: 6 additions & 0 deletions src/org/perl6/nqp/sixmodel/reprs/VMArray.java
Expand Up @@ -17,4 +17,10 @@ public SixModelObject allocate(ThreadContext tc, STable st) {
obj.st = st;
return obj;
}

public SixModelObject deserialize_stub(ThreadContext tc, STable st) {
SixModelObject obj = new VMArrayInstance();
obj.st = st;
return obj;
}
}
9 changes: 9 additions & 0 deletions src/org/perl6/nqp/sixmodel/reprs/VMHash.java
@@ -1,5 +1,7 @@
package org.perl6.nqp.sixmodel.reprs;

import java.util.HashMap;

import org.perl6.nqp.runtime.ThreadContext;
import org.perl6.nqp.sixmodel.*;

Expand All @@ -21,4 +23,11 @@ public SixModelObject allocate(ThreadContext tc, STable st) {
public StorageSpec get_value_storage_spec(ThreadContext tc, STable st) {
return new StorageSpec();
}

public SixModelObject deserialize_stub(ThreadContext tc, STable st) {
VMHashInstance obj = new VMHashInstance();
obj.st = st;
obj.storage = new HashMap<String, SixModelObject>();
return obj;
}
}
4 changes: 4 additions & 0 deletions src/org/perl6/nqp/sixmodel/reprs/VMIter.java
Expand Up @@ -25,4 +25,8 @@ public SixModelObject allocate(ThreadContext tc, STable st) {
public StorageSpec get_value_storage_spec(ThreadContext tc, STable st) {
return new StorageSpec();
}

public SixModelObject deserialize_stub(ThreadContext tc, STable st) {
throw new RuntimeException("VMIter does not participate in serialization");
}
}

0 comments on commit 9516dc1

Please sign in to comment.