Skip to content

Commit

Permalink
[JVM] Don't throw bare exceptions from (de)serialization ops
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaiepi committed Aug 9, 2022
1 parent f14c571 commit 3abee01
Showing 1 changed file with 48 additions and 44 deletions.
92 changes: 48 additions & 44 deletions src/vm/jvm/runtime/org/raku/nqp/runtime/Ops.java
Original file line number Diff line number Diff line change
Expand Up @@ -5340,32 +5340,40 @@ public static SixModelObject serializetobuf(SixModelObject scRef, SixModelObject
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) throws IOException {
if (scRef instanceof SCRefInstance) {
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;
}
public static String deserialize(
String blob,
SixModelObject scRef,
SixModelObject sh,
SixModelObject cr,
SixModelObject conflict,
ThreadContext tc
) {
if (!(scRef instanceof SCRefInstance))
throw ExceptionHandling.dieInternal(tc, "deserialize was not passed a valid SCRef");
SerializationContext sc = ((SCRefInstance)scRef).referencedSC;

CodeRef[] crArray;
int crCount;
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;
}

CompilationUnit cu = tc.curFrame.codeRef.staticInfo.compUnit;
if (isnull(cr) == 1) {
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);
}
CompilationUnit cu = tc.curFrame.codeRef.staticInfo.compUnit;
CodeRef[] crArray;
int crCount;
if (isnull(cr) == 1) {
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);
}

ByteBuffer binaryBlob;
if (blob == null) {
ByteBuffer binaryBlob;
if (blob == null)
try {
Class<?> cuKlass = cu.getClass();
String cuName = cuKlass.getSimpleName();
InputStream cuStream = cuKlass.getResourceAsStream(cuName + ".serialized.lz4");
Expand All @@ -5377,25 +5385,24 @@ public static String deserialize(String blob, SixModelObject scRef, SixModelObje
binaryBlob = LibraryLoader.readToHeapBuffer(cuStream);
}
}
catch (IOException e) {
throw ExceptionHandling.dieInternal(tc, e);
}
finally {
cuStream.close();
}
} else {
}
catch (IOException e) {
throw ExceptionHandling.dieInternal(tc, e);
}
else
try {
binaryBlob = Base64.decode(blob);
}
catch (IllegalArgumentException e) {
throw ExceptionHandling.dieInternal(tc, e);
}

SerializationReader sr = new SerializationReader(
tc, sc, shArray, crArray, crCount, binaryBlob);
sr.deserialize();

return blob;
}
else {
throw ExceptionHandling.dieInternal(tc, "deserialize was not passed a valid SCRef");
}
SerializationReader sr = new SerializationReader(tc, sc, shArray, crArray, crCount, binaryBlob);
sr.deserialize();
return blob;
}
public static SixModelObject wval(String sc, long idx, ThreadContext tc) {
return tc.gc.scs.get(sc).getObject((int)idx);
Expand Down Expand Up @@ -6502,16 +6509,13 @@ public static String loadbytecode(String filename, ThreadContext tc) {
LibraryLoader.load(tc, filename);
return filename;
}
public static SixModelObject loadbytecodebuffer(SixModelObject buffer, ThreadContext tc) throws Exception {
if (buffer instanceof VMArrayInstance_i8) {
public static SixModelObject loadbytecodebuffer(SixModelObject buffer, ThreadContext tc) {
if (buffer instanceof VMArrayInstance_i8)
LibraryLoader.load(tc, ((VMArrayInstance_i8)buffer).slots);
}
else if (buffer instanceof VMArrayInstance_u8) {
else if (buffer instanceof VMArrayInstance_u8)
LibraryLoader.load(tc, ((VMArrayInstance_u8)buffer).slots);
}
else {
throw new RuntimeException("Must pass a uint8 or int8 buffer to loadbytecodebuffer");
}
else
throw ExceptionHandling.dieInternal(tc, "loadbytecodebuffer expects a uint8 or int8 VMArray");
return buffer;
}
public static SixModelObject settypehll(SixModelObject type, String language, ThreadContext tc) {
Expand Down

0 comments on commit 3abee01

Please sign in to comment.