Created
May 15, 2016 10:12
-
-
Save niner/44ab8449ab5b9d0837dca69e525a59f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/vm/jvm/QAST/Compiler.nqp b/src/vm/jvm/QAST/Compiler.nqp | |
index bcf1ac3..3a095e3 100644 | |
--- a/src/vm/jvm/QAST/Compiler.nqp | |
+++ b/src/vm/jvm/QAST/Compiler.nqp | |
@@ -3366,7 +3366,9 @@ class QAST::CompilerJAST { | |
} | |
# If we need to do deserialization, emit code for that. | |
+ nqp::sayfh(nqp::getstderr(), $*COMP_MODE || "no comp mode"); | |
if $*COMP_MODE { | |
+ nqp::sayfh(nqp::getstderr(), "emitting deserialization code"); | |
$block.push(self.deserialization_code($cu.sc(), $cu.code_ref_blocks(), | |
$cu.repo_conflict_resolver())); | |
} | |
@@ -3525,6 +3527,11 @@ class QAST::CompilerJAST { | |
# Overall deserialization QAST. | |
QAST::Stmts.new( | |
QAST::Op.new( | |
+ :op('sayfh'), | |
+ QAST::Op.new( :op('getstderr') ), | |
+ QAST::SVal.new( :value('deserialization QAST') ) | |
+ ), | |
+ QAST::Op.new( | |
:op('bind'), | |
QAST::Var.new( :name('cur_sc'), :scope('local'), :decl('var') ), | |
QAST::Op.new( :op('createsc'), QAST::SVal.new( :value(nqp::scgethandle($sc)) ) ) | |
diff --git a/src/vm/jvm/runtime/org/perl6/nqp/runtime/CompilationUnit.java b/src/vm/jvm/runtime/org/perl6/nqp/runtime/CompilationUnit.java | |
index 68b5ede..b5e4aff 100644 | |
--- a/src/vm/jvm/runtime/org/perl6/nqp/runtime/CompilationUnit.java | |
+++ b/src/vm/jvm/runtime/org/perl6/nqp/runtime/CompilationUnit.java | |
@@ -93,6 +93,7 @@ public abstract class CompilationUnit { | |
ann.sLexicalNames().length == 0 ? null : ann.sLexicalNames(), | |
m.handlers, ann.argsExpectation()); | |
cr.staticInfo.methodName = m.methodName; | |
+ System.err.println("methodName: " + m.methodName); | |
cr.staticInfo.hasExitHandler = ann.hasExitHandler(); | |
cr.staticInfo.isThunk = ann.isThunk(); | |
cr.st = BOOTCodeSTable; | |
@@ -130,21 +131,31 @@ public abstract class CompilationUnit { | |
/* Get HLL configuration object. */ | |
hllConfig = tc.gc.getHLLConfigFor(this.hllName()); | |
+ System.err.println("hllName: " + this.hllName()); | |
/* Run any deserialization code. */ | |
CodeRef desCodeRef = null; | |
+ System.err.println("deserializeQbid: " + deserializeQbid()); | |
if (deserializeQbid() >= 0) | |
desCodeRef = lookupCodeRef(deserializeQbid()); | |
- if (desCodeRef != null) | |
+ if (desCodeRef != null) { | |
+ System.err.println("have a desCodeRef!"); | |
try { | |
Ops.invokeArgless(tc, desCodeRef); | |
+ System.err.println("survived desCodeRef!"); | |
} | |
catch (ControlException e) { | |
+ System.err.println("ControlException: " + e.toString()); | |
throw e; | |
} | |
catch (Exception e) { | |
+ System.err.println("Exception: " + e.toString()); | |
throw ExceptionHandling.dieInternal(tc, e.toString()); | |
} | |
+ } | |
+ else { | |
+ System.err.println("no desCodeRef found!"); | |
+ } | |
} | |
private static class ReflectiveCodeInfo { | |
diff --git a/src/vm/jvm/runtime/org/perl6/nqp/runtime/LibraryLoader.java b/src/vm/jvm/runtime/org/perl6/nqp/runtime/LibraryLoader.java | |
index 4cec2bf..14c785f 100644 | |
--- a/src/vm/jvm/runtime/org/perl6/nqp/runtime/LibraryLoader.java | |
+++ b/src/vm/jvm/runtime/org/perl6/nqp/runtime/LibraryLoader.java | |
@@ -59,6 +59,29 @@ public class LibraryLoader { | |
} | |
} | |
+ public static Class<?> loadPrecompiled(byte[] buffer) throws Exception { | |
+ // This is a (non-empty, non-self-extracting) zip file | |
+ // These are quite constrained for now | |
+ | |
+ JarEntry je; | |
+ JarInputStream jis = new JarInputStream(new ByteArrayInputStream(buffer)); | |
+ byte[] kl = null; | |
+ byte[] ser = null; | |
+ | |
+ while ((je = jis.getNextJarEntry()) != null) { | |
+ byte[] data = readEverything(jis); | |
+ | |
+ if (je.getName().endsWith(".class") && kl == null) kl = data; | |
+ else if (je.getName().endsWith(".serialized") && ser == null) ser = data; | |
+ else throw new RuntimeException("Bytecode jar contains unexpected file "+je.getName()); | |
+ } | |
+ | |
+ if (kl == null) throw new RuntimeException("Bytecode jar lacks class file"); | |
+ if (ser == null) throw new RuntimeException("Bytecode jar lacks serialization file"); | |
+ | |
+ return loadNew(kl, ser); | |
+ } | |
+ | |
public static Class<?> loadFile(String cf, boolean shared) throws Exception { | |
if (shared) { | |
synchronized(sharedClassHash) { | |
@@ -80,26 +103,7 @@ public class LibraryLoader { | |
return loadNew(b, null); | |
} else if (sig == 0x504B0304) { | |
- // This is a (non-empty, non-self-extracting) zip file | |
- // These are quite constrained for now | |
- | |
- JarEntry je; | |
- JarInputStream jis = new JarInputStream(new ByteArrayInputStream(b)); | |
- byte[] kl = null; | |
- byte[] ser = null; | |
- | |
- while ((je = jis.getNextJarEntry()) != null) { | |
- byte[] data = readEverything(jis); | |
- | |
- if (je.getName().endsWith(".class") && kl == null) kl = data; | |
- else if (je.getName().endsWith(".serialized") && ser == null) ser = data; | |
- else throw new RuntimeException("Bytecode jar contains unexpected file "+je.getName()); | |
- } | |
- | |
- if (kl == null) throw new RuntimeException("Bytecode jar lacks class file"); | |
- if (ser == null) throw new RuntimeException("Bytecode jar lacks serialization file"); | |
- | |
- return loadNew(kl, ser); | |
+ return loadPrecompiled(b); | |
} else { | |
throw new RuntimeException("Unrecognized bytecode format in "+cf); | |
} | |
@@ -119,11 +123,13 @@ public class LibraryLoader { | |
} | |
public Class<?> loadClass() { | |
+ System.err.println("loadClass()" + bytes); | |
return defineClass(null, this.bytes, 0, this.bytes.length); | |
} | |
@Override | |
public InputStream getResourceAsStream(String name) { | |
+ System.err.println("getResourceAsStream(" + name + "): " + serial); | |
return new ByteArrayInputStream(serial); | |
} | |
} | |
diff --git a/src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java b/src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java | |
index 6473401..c0da7ae 100644 | |
--- a/src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java | |
+++ b/src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java | |
@@ -4722,6 +4722,7 @@ public final class Ops { | |
} | |
} | |
public static String deserialize(String blob, SixModelObject scRef, SixModelObject sh, SixModelObject cr, SixModelObject conflict, ThreadContext tc) throws IOException { | |
+ System.err.println("deserialize()"); | |
if (scRef instanceof SCRefInstance) { | |
SerializationContext sc = ((SCRefInstance)scRef).referencedSC; | |
@@ -4747,8 +4748,10 @@ public final class Ops { | |
ByteBuffer binaryBlob; | |
if (blob == null) { | |
+ System.err.println("blob is null"); | |
binaryBlob = ByteBuffer.wrap( LibraryLoader.readEverything( cu.getClass().getResourceAsStream( cu.getClass().getSimpleName() + ".serialized" ) ) ); | |
} else { | |
+ System.err.println("got a blob"); | |
binaryBlob = Base64.decode(blob); | |
} | |
@@ -5636,13 +5639,21 @@ public final class Ops { | |
return value; | |
} | |
public static String loadbytecode(String filename, ThreadContext tc) { | |
+ System.err.println("loadbytecode(" + filename + ")"); | |
new LibraryLoader().load(tc, filename); | |
return filename; | |
} | |
- public static SixModelObject loadbytecodebuffer(SixModelObject buffer, ThreadContext tc) { | |
+ public static SixModelObject loadbytecodebuffer(SixModelObject buffer, ThreadContext tc) throws Exception { | |
if (buffer instanceof VMArrayInstance_i8) { | |
- byte[] serial = new byte[0]; | |
- new LibraryLoader().loadNew(((VMArrayInstance_i8)buffer).slots, serial); | |
+ System.err.println("i8 loadPrecompiled() " + ((VMArrayInstance_i8)buffer).slots[0] + ((VMArrayInstance_i8)buffer).slots[1] + ((VMArrayInstance_i8)buffer).slots[2] + ((VMArrayInstance_i8)buffer).slots[3]); | |
+ new LibraryLoader().loadPrecompiled(((VMArrayInstance_i8)buffer).slots); | |
+ } | |
+ else if (buffer instanceof VMArrayInstance_u8) { | |
+ System.err.println("u8 loadPrecompiled() " + ((VMArrayInstance_u8)buffer).slots[0] + ((VMArrayInstance_u8)buffer).slots[1] + ((VMArrayInstance_u8)buffer).slots[2] + ((VMArrayInstance_u8)buffer).slots[3]); | |
+ new LibraryLoader().loadPrecompiled(((VMArrayInstance_u8)buffer).slots); | |
+ } | |
+ else { | |
+ throw new RuntimeException("Must pass a uint8 or int8 buffer to loadbytecodebuffer"); | |
} | |
return buffer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment