Skip to content

Commit

Permalink
Let's try that again, this time without breaking the API.
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Jun 21, 2013
1 parent 8c2ec14 commit cda5cc2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
12 changes: 9 additions & 3 deletions src/vm/jvm/QAST/Compiler.nqp
Expand Up @@ -2017,7 +2017,7 @@ QAST::OperationsJAST.map_classlib_core_op('scobjcount', $TYPE_OPS, 'scobjcount',
QAST::OperationsJAST.map_classlib_core_op('setobjsc', $TYPE_OPS, 'setobjsc', [$RT_OBJ, $RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('getobjsc', $TYPE_OPS, 'getobjsc', [$RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('serialize', $TYPE_OPS, 'serialize', [$RT_OBJ, $RT_OBJ], $RT_STR, :tc);
QAST::OperationsJAST.map_classlib_core_op('deserialize', $TYPE_OPS, 'deserialize', [$RT_STR, $RT_OBJ, $RT_OBJ, $RT_INT, $RT_OBJ], $RT_STR, :tc);
QAST::OperationsJAST.map_classlib_core_op('deserialize', $TYPE_OPS, 'deserialize', [$RT_STR, $RT_OBJ, $RT_OBJ, $RT_OBJ, $RT_OBJ], $RT_STR, :tc);
QAST::OperationsJAST.map_classlib_core_op('wval', $TYPE_OPS, 'wval', [$RT_STR, $RT_INT], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('scwbdisable', $TYPE_OPS, 'scwbdisable', [], $RT_INT, :tc);
QAST::OperationsJAST.map_classlib_core_op('scwbenable', $TYPE_OPS, 'scwbenable', [], $RT_INT, :tc);
Expand Down Expand Up @@ -2968,7 +2968,13 @@ class QAST::CompilerJAST {
QAST::SVal.new( :value('Repossession conflicts occurred during deserialization') )
);
}


# Which of our methods need to be serialized?
my $count_meth := JAST::Method.new( :name('serializedCodeRefCount'), :returns('I'), :static(0) );
$count_meth.append(JAST::PushIndex.new( :value(+@code_ref_blocks) ));
$count_meth.append($IRETURN);
$*JCLASS.add_method($count_meth);

# Overall deserialization QAST.
QAST::Stmts.new(
QAST::Op.new(
Expand All @@ -2991,7 +2997,7 @@ class QAST::CompilerJAST {
QAST::SVal.new( :value($serialized) ),
QAST::Var.new( :name('cur_sc'), :scope('local') ),
$sh_ast,
QAST::IVal.new( :value(+@code_ref_blocks) ),
QAST::Op.new( :op('null') ),
QAST::Var.new( :name('conflicts'), :scope('local') )
),
QAST::Op.new(
Expand Down
4 changes: 4 additions & 0 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/CompilationUnit.java
Expand Up @@ -299,4 +299,8 @@ public String entryCuid() { /*FOR_STAGE0*/
public int entryQbid() {
return -1;
}

public int serializedCodeRefCount() {
return -1;
}
}
41 changes: 16 additions & 25 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -3057,7 +3057,7 @@ public static String serialize(SixModelObject scRef, SixModelObject sh, ThreadCo
throw ExceptionHandling.dieInternal(tc, "serialize was not passed a valid SCRef");
}
}
public static String deserialize(String blob, SixModelObject scRef, SixModelObject sh, SixModelObject cr, SixModelObject conflict, ThreadContext tc) { /*FOR_STAGE0*/
public static String deserialize(String blob, SixModelObject scRef, SixModelObject sh, SixModelObject cr, SixModelObject conflict, ThreadContext tc) {
if (scRef instanceof SCRefInstance) {
SerializationContext sc = ((SCRefInstance)scRef).referencedSC;

Expand All @@ -3067,12 +3067,22 @@ public static String deserialize(String blob, SixModelObject scRef, SixModelObje
shArray[i] = tc.native_s;
}

CodeRef[] crArray = new CodeRef[(int)cr.elems(tc)];
for (int i = 0; i < crArray.length; i++)
crArray[i] = (CodeRef)cr.at_pos_boxed(tc, i);

CodeRef[] crArray;
int crCount;

if (cr == null) {
CompilationUnit cu = tc.curFrame.codeRef.staticInfo.compUnit;
crArray = cu.qbidToCodeRef;
crCount = cu.serializedCodeRefCount();
} else {
crArray = new CodeRef[(int)cr.elems(tc)];
crCount = crArray.length;
for (int i = 0; i < crArray.length; i++)
crArray[i] = (CodeRef)cr.at_pos_boxed(tc, i);
}

SerializationReader sr = new SerializationReader(
tc, sc, shArray, crArray, crArray.length,
tc, sc, shArray, crArray, crCount,
Base64.decode(blob));
sr.deserialize();

Expand All @@ -3082,25 +3092,6 @@ public static String deserialize(String blob, SixModelObject scRef, SixModelObje
throw ExceptionHandling.dieInternal(tc, "deserialize was not passed a valid SCRef");
}
}
public static String deserialize(String blob, SixModelObject scRef, SixModelObject sh, long crCount, SixModelObject conflict, ThreadContext tc) {
if (!(scRef instanceof SCRefInstance))
throw ExceptionHandling.dieInternal(tc, "deserialize was not passed a valid SCRef");

SerializationContext sc = ((SCRefInstance)scRef).referencedSC;

String[] shArray = new String[(int)sh.elems(tc)];
for (int i = 0; i < shArray.length; i++) {
sh.at_pos_native(tc, i);
shArray[i] = tc.native_s;
}

SerializationReader sr = new SerializationReader(
tc, sc, shArray, tc.curFrame.codeRef.staticInfo.compUnit.qbidToCodeRef,
(int)crCount, Base64.decode(blob));
sr.deserialize();

return blob;
}
public static SixModelObject wval(String sc, long idx, ThreadContext tc) {
return tc.gc.scs.get(sc).root_objects.get((int)idx);
}
Expand Down

0 comments on commit cda5cc2

Please sign in to comment.