Skip to content

Commit

Permalink
VMArray should serialize its type.
Browse files Browse the repository at this point in the history
This fixes the issue with the utf8/utf16/utf32 types in the new Buf
implementation.
  • Loading branch information
jnthn committed Jul 20, 2013
1 parent 173dc64 commit 8f912e2
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
Expand Up @@ -11,7 +11,7 @@

public class SerializationReader {
/* The current version of the serialization format. */
private final int CURRENT_VERSION = 6;
private final int CURRENT_VERSION = 7;

/* The minimum version of the serialization format. */
private final int MIN_VERSION = 4;
Expand Down
Expand Up @@ -18,7 +18,7 @@

public class SerializationWriter {
/* The current version of the serialization format. */
private final int CURRENT_VERSION = 6;
private final int CURRENT_VERSION = 7;

/* Various sizes (in bytes). */
private final int HEADER_SIZE = 4 * 16;
Expand Down
45 changes: 39 additions & 6 deletions src/vm/jvm/runtime/org/perl6/nqp/sixmodel/reprs/VMArray.java
Expand Up @@ -25,7 +25,7 @@ public SixModelObject allocate(ThreadContext tc, STable st) {
obj = new VMArrayInstance();
}
else {
switch (((StorageSpec)st.REPRData).boxed_primitive) {
switch (((VMArrayREPRData)st.REPRData).ss.boxed_primitive) {
case StorageSpec.BP_INT:
obj = new VMArrayInstance_i();
break;
Expand All @@ -52,7 +52,10 @@ public void compose(ThreadContext tc, STable st, SixModelObject repr_info) {
case StorageSpec.BP_INT:
case StorageSpec.BP_NUM:
case StorageSpec.BP_STR:
st.REPRData = ss;
VMArrayREPRData reprData = new VMArrayREPRData();
reprData.type = type;
reprData.ss = ss;
st.REPRData = reprData;
break;
default:
if (ss.inlineable != StorageSpec.REFERENCE)
Expand All @@ -67,7 +70,7 @@ public SixModelObject deserialize_stub(ThreadContext tc, STable st) {
obj = new VMArrayInstance();
}
else {
switch (((StorageSpec)st.REPRData).boxed_primitive) {
switch (((VMArrayREPRData)st.REPRData).ss.boxed_primitive) {
case StorageSpec.BP_INT:
obj = new VMArrayInstance_i();
break;
Expand All @@ -93,8 +96,9 @@ public void deserialize_finish(ThreadContext tc, STable st,
obj.bind_pos_boxed(tc, i, reader.readRef());
}
else {
short boxPrim = ((VMArrayREPRData)st.REPRData).ss.boxed_primitive;
for (long i = 0; i < elems; i++) {
switch (((StorageSpec)obj.st.REPRData).boxed_primitive) {
switch (boxPrim) {
case StorageSpec.BP_INT:
tc.native_i = reader.readLong();
break;
Expand All @@ -120,9 +124,10 @@ public void serialize(ThreadContext tc, SerializationWriter writer, SixModelObje
writer.writeRef(obj.at_pos_boxed(tc, i));
}
else {
short boxPrim = ((VMArrayREPRData)obj.st.REPRData).ss.boxed_primitive;
for (long i = 0; i < elems; i++) {
obj.at_pos_native(tc, i);
switch (((StorageSpec)obj.st.REPRData).boxed_primitive) {
switch (boxPrim) {
case StorageSpec.BP_INT:
writer.writeInt(tc.native_i);
break;
Expand All @@ -140,6 +145,34 @@ public void serialize(ThreadContext tc, SerializationWriter writer, SixModelObje
}

public StorageSpec get_value_storage_spec(ThreadContext tc, STable st) {
return st.REPRData == null ? StorageSpec.BOXED : (StorageSpec)st.REPRData;
return st.REPRData == null ? StorageSpec.BOXED : ((VMArrayREPRData)st.REPRData).ss;
}

/**
* REPR data serialization. Serializes the per-type representation data that
* is attached to the supplied STable.
*/
public void serialize_repr_data(ThreadContext tc, STable st, SerializationWriter writer)
{
writer.writeRef(st.REPRData == null
? null
: ((VMArrayREPRData)st.REPRData).type);
}

/**
* REPR data deserialization. Deserializes the per-type representation data and
* attaches it to the supplied STable.
*/
public void deserialize_repr_data(ThreadContext tc, STable st, SerializationReader reader)
{
if (reader.version >= 7) {
SixModelObject type = reader.readRef();
if (type != null) {
VMArrayREPRData reprData = new VMArrayREPRData();
reprData.type = type;
reprData.ss = type.st.REPR.get_storage_spec(tc, type.st);
st.REPRData = reprData;
}
}
}
}
@@ -0,0 +1,9 @@
package org.perl6.nqp.sixmodel.reprs;

import org.perl6.nqp.sixmodel.SixModelObject;
import org.perl6.nqp.sixmodel.StorageSpec;

public class VMArrayREPRData {
public StorageSpec ss;
public SixModelObject type;
}

0 comments on commit 8f912e2

Please sign in to comment.