Permalink
Browse files

First stab at serializable AST via Externalizable. Still not faster t…

…han parsing.
  • Loading branch information...
1 parent 60f553c commit ee7db8e38fe04921f2ee74947f97ef6ceee71b11 @headius headius committed Jun 15, 2010
Showing with 3,029 additions and 180 deletions.
  1. +4 −1 lib/ruby/site_ruby/1.8/rubygems/source_index.rb
  2. +2 −0 lib/ruby/site_ruby/1.8/rubygems/specification.rb
  3. +69 −4 src/org/jruby/Ruby.java
  4. +12 −0 src/org/jruby/RubyInstanceConfig.java
  5. +20 −0 src/org/jruby/ast/AliasNode.java
  6. +22 −2 src/org/jruby/ast/AndNode.java
  7. +20 −0 src/org/jruby/ast/ArgAuxillaryNode.java
  8. +22 −2 src/org/jruby/ast/ArgsCatNode.java
  9. +5 −0 src/org/jruby/ast/ArgsNoArgNode.java
  10. +60 −13 src/org/jruby/ast/ArgsNode.java
  11. +5 −0 src/org/jruby/ast/ArgsPreOneArgNode.java
  12. +5 −0 src/org/jruby/ast/ArgsPreTwoArgNode.java
  13. +20 −0 src/org/jruby/ast/ArgsPushNode.java
  14. +18 −0 src/org/jruby/ast/ArgumentNode.java
  15. +18 −0 src/org/jruby/ast/ArrayNode.java
  16. +18 −0 src/org/jruby/ast/AssignableNode.java
  17. +27 −1 src/org/jruby/ast/AttrAssignNode.java
  18. +18 −0 src/org/jruby/ast/AttrAssignOneArgNode.java
  19. +23 −1 src/org/jruby/ast/AttrAssignThreeArgNode.java
  20. +20 −0 src/org/jruby/ast/AttrAssignTwoArgNode.java
  21. +19 −1 src/org/jruby/ast/BackRefNode.java
  22. +19 −1 src/org/jruby/ast/BeginNode.java
  23. +18 −0 src/org/jruby/ast/BignumNode.java
  24. +19 −0 src/org/jruby/ast/BlockArg18Node.java
  25. +21 −1 src/org/jruby/ast/BlockArgNode.java
  26. +5 −0 src/org/jruby/ast/BlockNode.java
  27. +21 −1 src/org/jruby/ast/BlockPassNode.java
  28. +19 −1 src/org/jruby/ast/BreakNode.java
  29. +5 −0 src/org/jruby/ast/CallManyArgsBlockNode.java
  30. +5 −0 src/org/jruby/ast/CallManyArgsBlockPassNode.java
  31. +6 −1 src/org/jruby/ast/CallManyArgsNode.java
  32. +5 −0 src/org/jruby/ast/CallNoArgBlockNode.java
  33. +5 −0 src/org/jruby/ast/CallNoArgBlockPassNode.java
  34. +5 −0 src/org/jruby/ast/CallNoArgNode.java
  35. +25 −1 src/org/jruby/ast/CallNode.java
  36. +18 −0 src/org/jruby/ast/CallOneArgBlockNode.java
  37. +18 −0 src/org/jruby/ast/CallOneArgBlockPassNode.java
  38. +18 −0 src/org/jruby/ast/CallOneArgFixnumNode.java
  39. +19 −1 src/org/jruby/ast/CallOneArgNode.java
  40. +5 −0 src/org/jruby/ast/CallSpecialArgBlockNode.java
  41. +5 −0 src/org/jruby/ast/CallSpecialArgBlockPassNode.java
  42. +5 −0 src/org/jruby/ast/CallSpecialArgNode.java
  43. +23 −1 src/org/jruby/ast/CallThreeArgBlockNode.java
  44. +23 −1 src/org/jruby/ast/CallThreeArgBlockPassNode.java
  45. +22 −0 src/org/jruby/ast/CallThreeArgNode.java
  46. +21 −1 src/org/jruby/ast/CallTwoArgBlockNode.java
  47. +21 −1 src/org/jruby/ast/CallTwoArgBlockPassNode.java
  48. +20 −0 src/org/jruby/ast/CallTwoArgNode.java
  49. +24 −2 src/org/jruby/ast/CaseNode.java
  50. +28 −4 src/org/jruby/ast/ClassNode.java
  51. +18 −0 src/org/jruby/ast/ClassVarAsgnNode.java
  52. +18 −0 src/org/jruby/ast/ClassVarDeclNode.java
  53. +18 −0 src/org/jruby/ast/ClassVarNode.java
  54. +6 −4 src/org/jruby/ast/Colon2ConstNode.java
  55. +5 −0 src/org/jruby/ast/Colon2ImplicitNode.java
  56. +5 −1 src/org/jruby/ast/Colon2MethodNode.java
  57. +19 −1 src/org/jruby/ast/Colon2Node.java
  58. +20 −2 src/org/jruby/ast/Colon3Node.java
  59. +22 −2 src/org/jruby/ast/ConstDeclNode.java
  60. +19 −1 src/org/jruby/ast/ConstNode.java
  61. +20 −0 src/org/jruby/ast/DAsgnNode.java
  62. +23 −3 src/org/jruby/ast/DRegexpNode.java
  63. +5 −0 src/org/jruby/ast/DStrNode.java
  64. +5 −0 src/org/jruby/ast/DSymbolNode.java
  65. +20 −0 src/org/jruby/ast/DVarNode.java
  66. +5 −0 src/org/jruby/ast/DXStrNode.java
  67. +19 −1 src/org/jruby/ast/DefinedNode.java
  68. +5 −0 src/org/jruby/ast/DefnNode.java
  69. +20 −1 src/org/jruby/ast/DefsNode.java
  70. +28 −4 src/org/jruby/ast/DotNode.java
  71. +5 −0 src/org/jruby/ast/EncodingNode.java
  72. +22 −2 src/org/jruby/ast/EnsureNode.java
  73. +19 −1 src/org/jruby/ast/EvStrNode.java
  74. +5 −0 src/org/jruby/ast/FCallManyArgsBlockNode.java
  75. +5 −0 src/org/jruby/ast/FCallManyArgsBlockPassNode.java
  76. +5 −1 src/org/jruby/ast/FCallManyArgsNode.java
  77. +5 −0 src/org/jruby/ast/FCallNoArgBlockNode.java
  78. +5 −0 src/org/jruby/ast/FCallNoArgBlockPassNode.java
  79. +5 −0 src/org/jruby/ast/FCallNoArgNode.java
  80. +22 −0 src/org/jruby/ast/FCallNode.java
  81. +18 −0 src/org/jruby/ast/FCallOneArgBlockNode.java
  82. +18 −0 src/org/jruby/ast/FCallOneArgBlockPassNode.java
  83. +18 −0 src/org/jruby/ast/FCallOneArgNode.java
  84. +5 −0 src/org/jruby/ast/FCallSpecialArgBlockNode.java
  85. +5 −0 src/org/jruby/ast/FCallSpecialArgBlockPassNode.java
  86. +5 −0 src/org/jruby/ast/FCallSpecialArgNode.java
  87. +22 −0 src/org/jruby/ast/FCallThreeArgBlockNode.java
  88. +22 −0 src/org/jruby/ast/FCallThreeArgBlockPassNode.java
  89. +22 −0 src/org/jruby/ast/FCallThreeArgNode.java
  90. +20 −0 src/org/jruby/ast/FCallTwoArgBlockNode.java
  91. +20 −0 src/org/jruby/ast/FCallTwoArgBlockPassNode.java
  92. +20 −0 src/org/jruby/ast/FCallTwoArgNode.java
  93. +5 −0 src/org/jruby/ast/FalseNode.java
  94. +5 −0 src/org/jruby/ast/FileNode.java
  95. +17 −1 src/org/jruby/ast/FixnumNode.java
  96. +28 −4 src/org/jruby/ast/FlipNode.java
  97. +18 −0 src/org/jruby/ast/FloatNode.java
  98. +18 −0 src/org/jruby/ast/ForNode.java
  99. +18 −0 src/org/jruby/ast/GlobalAsgnNode.java
  100. +18 −0 src/org/jruby/ast/GlobalVarNode.java
  101. +4 −0 src/org/jruby/ast/Hash19Node.java
  102. +19 −1 src/org/jruby/ast/HashNode.java
  103. +25 −3 src/org/jruby/ast/IfNode.java
  104. +19 −1 src/org/jruby/ast/InstAsgnNode.java
  105. +19 −1 src/org/jruby/ast/InstVarNode.java
  106. +30 −4 src/org/jruby/ast/IterNode.java
  107. +5 −0 src/org/jruby/ast/LambdaNode.java
  108. +26 −0 src/org/jruby/ast/ListNode.java
  109. +17 −0 src/org/jruby/ast/LiteralNode.java
  110. +21 −1 src/org/jruby/ast/LocalAsgnNode.java
  111. +21 −1 src/org/jruby/ast/LocalVarNode.java
  112. +22 −2 src/org/jruby/ast/Match2Node.java
  113. +23 −3 src/org/jruby/ast/Match3Node.java
  114. +19 −1 src/org/jruby/ast/MatchNode.java
  115. +28 −4 src/org/jruby/ast/MethodDefNode.java
  116. +25 −3 src/org/jruby/ast/ModuleNode.java
  117. +28 −4 src/org/jruby/ast/MultipleAsgn19Node.java
  118. +22 −2 src/org/jruby/ast/MultipleAsgnNode.java
  119. +19 −1 src/org/jruby/ast/NewlineNode.java
  120. +19 −1 src/org/jruby/ast/NextNode.java
  121. +1 −0 src/org/jruby/ast/NilImplicitNode.java
  122. +5 −0 src/org/jruby/ast/NilNode.java
  123. +17 −1 src/org/jruby/ast/Node.java
  124. +19 −1 src/org/jruby/ast/NotNode.java
  125. +19 −1 src/org/jruby/ast/NthRefNode.java
  126. +22 −2 src/org/jruby/ast/OpAsgnAndNode.java
  127. +31 −5 src/org/jruby/ast/OpAsgnNode.java
  128. +22 −2 src/org/jruby/ast/OpAsgnOrNode.java
  129. +34 −6 src/org/jruby/ast/OpElementAsgnNode.java
  130. +18 −0 src/org/jruby/ast/OpElementOneArgAndAsgnNode.java
  131. +18 −0 src/org/jruby/ast/OpElementOneArgAsgnNode.java
  132. +18 −0 src/org/jruby/ast/OpElementOneArgOrAsgnNode.java
  133. +17 −0 src/org/jruby/ast/OptArgNode.java
  134. +22 −2 src/org/jruby/ast/OrNode.java
  135. +5 −0 src/org/jruby/ast/PostExeNode.java
  136. +5 −0 src/org/jruby/ast/PreExeNode.java
  137. +5 −0 src/org/jruby/ast/RedoNode.java
  138. +23 −3 src/org/jruby/ast/RegexpNode.java
  139. +25 −3 src/org/jruby/ast/RescueBodyNode.java
  140. +25 −3 src/org/jruby/ast/RescueNode.java
  141. +18 −0 src/org/jruby/ast/RestArgNode.java
  142. +5 −0 src/org/jruby/ast/RetryNode.java
  143. +22 −4 src/org/jruby/ast/ReturnNode.java
  144. +20 −0 src/org/jruby/ast/RootNode.java
  145. +25 −3 src/org/jruby/ast/SClassNode.java
  146. +5 −1 src/org/jruby/ast/SValue19Node.java
  147. +19 −1 src/org/jruby/ast/SValueNode.java
  148. +5 −0 src/org/jruby/ast/SelfNode.java
  149. +4 −0 src/org/jruby/ast/Splat19Node.java
  150. +19 −1 src/org/jruby/ast/SplatNode.java
  151. +5 −0 src/org/jruby/ast/StarNode.java
  152. +19 −1 src/org/jruby/ast/StrNode.java
  153. +22 −3 src/org/jruby/ast/SuperNode.java
  154. +19 −1 src/org/jruby/ast/SymbolNode.java
  155. +19 −1 src/org/jruby/ast/ToAryNode.java
  156. +5 −0 src/org/jruby/ast/TrueNode.java
  157. +18 −0 src/org/jruby/ast/TypedArgumentNode.java
  158. +18 −0 src/org/jruby/ast/UndefNode.java
  159. +5 −0 src/org/jruby/ast/UnnamedRestArgNode.java
  160. +27 −3 src/org/jruby/ast/UntilNode.java
  161. +20 −0 src/org/jruby/ast/VAliasNode.java
  162. +19 −1 src/org/jruby/ast/VCallNode.java
  163. +26 −4 src/org/jruby/ast/WhenNode.java
  164. +5 −0 src/org/jruby/ast/WhenOneArgNode.java
  165. +27 −3 src/org/jruby/ast/WhileNode.java
  166. +19 −1 src/org/jruby/ast/XStrNode.java
  167. +22 −2 src/org/jruby/ast/YieldNode.java
  168. +19 −1 src/org/jruby/ast/YieldOneNode.java
  169. +25 −3 src/org/jruby/ast/YieldThreeNode.java
  170. +22 −2 src/org/jruby/ast/YieldTwoNode.java
  171. +5 −0 src/org/jruby/ast/ZArrayNode.java
  172. +19 −2 src/org/jruby/ast/ZSuperNode.java
  173. +5 −0 src/org/jruby/ast/ZYieldNode.java
  174. +5 −0 src/org/jruby/ast/ZeroArgNode.java
  175. +20 −3 src/org/jruby/lexer/yacc/ISourcePosition.java
  176. +21 −2 src/org/jruby/lexer/yacc/SimpleSourcePosition.java
  177. +4 −0 src/org/jruby/parser/BlockStaticScope.java
  178. +5 −0 src/org/jruby/parser/EvalStaticScope.java
  179. +4 −0 src/org/jruby/parser/LocalStaticScope.java
  180. +47 −3 src/org/jruby/parser/StaticScope.java
  181. +34 −1 src/org/jruby/runtime/load/ExternalScript.java
@@ -92,7 +92,10 @@ def load_specification(file_name)
end.untaint
begin
- gemspec = eval spec_code, binding, file_name
+ p "loading: #{file_name}"
+ Kernel.load file_name
+ gemspec = $last_gemspec
+ # gemspec = eval spec_code, binding, file_name
if gemspec.is_a?(Gem::Specification)
gemspec.loaded_from = file_name
@@ -425,6 +425,8 @@ def initialize name = nil, version = nil
yield self if block_given?
@@gather.call(self) if @@gather
+
+ $last_gemspec = self
end
##
View
@@ -57,7 +57,6 @@
import java.util.Stack;
import java.util.Vector;
import java.util.WeakHashMap;
-import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
@@ -126,9 +125,12 @@
import com.kenai.constantine.platform.Errno;
import java.io.ByteArrayOutputStream;
import java.io.File;
-import java.util.Arrays;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.ObjectOutputStream;
import java.util.EnumSet;
import java.util.concurrent.atomic.AtomicLong;
+import java.util.zip.GZIPOutputStream;
import org.jruby.ast.RootNode;
import org.jruby.exceptions.Unrescuable;
import org.jruby.internal.runtime.methods.DynamicMethod;
@@ -2529,19 +2531,82 @@ private void printErrorPos(ThreadContext context, PrintStream errorStream) {
}
}
}
-
+
public void loadFile(String scriptName, InputStream in, boolean wrap) {
IRubyObject self = wrap ? TopSelfFactory.createTopSelf(this) : getTopSelf();
ThreadContext context = getCurrentContext();
String file = context.getFile();
+
+ try {
+ secure(4); /* should alter global state */
+
+ context.setFile(scriptName);
+ context.preNodeEval(objectClass, self, scriptName);
+
+ Node node = parseFile(in, scriptName, null);
+
+ node.interpret(this, context, self, Block.NULL_BLOCK);
+ } catch (JumpException.ReturnJump rj) {
+ return;
+ } finally {
+ context.postNodeEval();
+ context.setFile(file);
+ }
+ }
+
+ public void loadFile(String scriptName, String filename, InputStream in, boolean wrap) {
+ IRubyObject self = wrap ? TopSelfFactory.createTopSelf(this) : getTopSelf();
+ ThreadContext context = getCurrentContext();
+ String file = context.getFile();
try {
secure(4); /* should alter global state */
context.setFile(scriptName);
context.preNodeEval(objectClass, self, scriptName);
- parseFile(in, scriptName, null).interpret(this, context, self, Block.NULL_BLOCK);
+ Node node = parseFile(in, scriptName, null);
+
+ if (config.getSaveRbjFiles()) {
+ try {
+ System.out.println("saving: " + filename + "j");
+ FileOutputStream fos = new FileOutputStream(filename + "j");
+// GZIPOutputStream zos = new GZIPOutputStream(fos);
+ ObjectOutputStream oos = new ObjectOutputStream(fos);
+ oos.writeObject(node);
+ oos.close();
+// zos.close();
+ fos.close();
+ } catch (FileNotFoundException fnfe) {
+ fnfe.printStackTrace();
+ } catch (IOException ioe) {
+ // ignore
+ ioe.printStackTrace();
+// } catch (Exception e) {
+// e.printStackTrace();
+ }
+ }
+ node.interpret(this, context, self, Block.NULL_BLOCK);
+ } catch (JumpException.ReturnJump rj) {
+ return;
+ } finally {
+ context.postNodeEval();
+ context.setFile(file);
+ }
+ }
+
+ public void loadFile(String scriptName, Node node, boolean wrap) {
+ IRubyObject self = wrap ? TopSelfFactory.createTopSelf(this) : getTopSelf();
+ ThreadContext context = getCurrentContext();
+ String file = context.getFile();
+
+ try {
+ secure(4); /* should alter global state */
+
+ context.setFile(scriptName);
+ context.preNodeEval(objectClass, self, scriptName);
+
+ node.interpret(this, context, self, Block.NULL_BLOCK);
} catch (JumpException.ReturnJump rj) {
return;
} finally {
@@ -202,6 +202,7 @@ public boolean shouldPrecompileAll() {
private String inPlaceBackupExtension = null;
private boolean parserDebug = false;
private String threadDumpSignal = null;
+ private boolean saveRbjFiles = false;
private int safeLevel = 0;
@@ -1171,6 +1172,9 @@ private void processArgument() {
INLINE_DYNCALL_ENABLED = true;
RubyException.TRACE_TYPE = RubyException.RUBY_COMPILED;
break FOR;
+ } else if (argument.equals("--rbj")) {
+ saveRbjFiles = true;
+ break FOR;
} else if (argument.equals("--1.9")) {
setCompatVersion(CompatVersion.RUBY1_9);
break FOR;
@@ -1548,4 +1552,12 @@ public ASTCompiler newCompiler() {
public String getThreadDumpSignal() {
return threadDumpSignal;
}
+
+ public boolean getSaveRbjFiles() {
+ return saveRbjFiles;
+ }
+
+ public void setSaveRbjFiles(boolean saveRbjFiles) {
+ this.saveRbjFiles = saveRbjFiles;
+ }
}
@@ -31,6 +31,9 @@
***** END LICENSE BLOCK *****/
package org.jruby.ast;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.util.List;
import org.jruby.Ruby;
@@ -44,9 +47,14 @@
/** Represents an alias statement (<code>alias newName oldName</code>).
*/
public class AliasNode extends Node {
+ private static final long serialVersionUID = 0L;
private Node oldName;
private Node newName;
+ public AliasNode() {
+ super();
+ }
+
public AliasNode(ISourcePosition position, Node newName, Node oldName) {
super(position);
this.oldName = oldName;
@@ -92,4 +100,16 @@ public IRubyObject interpret(Ruby runtime, ThreadContext context, IRubyObject se
return RuntimeHelpers.defineAlias(context, newerName, olderName);
}
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ super.writeExternal(out);
+ out.writeObject(oldName);
+ out.writeObject(newName);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ super.readExternal(in);
+ oldName = (Node)in.readObject();
+ newName = (Node)in.readObject();
+ }
}
@@ -31,6 +31,9 @@
***** END LICENSE BLOCK *****/
package org.jruby.ast;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.util.List;
import org.jruby.Ruby;
@@ -44,8 +47,13 @@
* Represents a && (and) operator.
*/
public class AndNode extends Node implements BinaryOperatorNode {
- private final Node firstNode;
- private final Node secondNode;
+ private static final long serialVersionUID = 0L;
+ private Node firstNode;
+ private Node secondNode;
+
+ public AndNode() {
+ super();
+ }
public AndNode(ISourcePosition position, Node firstNode, Node secondNode) {
super(position);
@@ -93,4 +101,16 @@ public IRubyObject interpret(Ruby runtime, ThreadContext context, IRubyObject se
return secondNode.interpret(runtime, context, self, aBlock);
}
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ super.writeExternal(out);
+ out.writeObject(firstNode);
+ out.writeObject(secondNode);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ super.readExternal(in);
+ firstNode = (Node)in.readObject();
+ secondNode = (Node)in.readObject();
+ }
}
@@ -27,6 +27,9 @@
***** END LICENSE BLOCK *****/
package org.jruby.ast;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.util.List;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
@@ -35,9 +38,14 @@
* @author enebo
*/
public class ArgAuxillaryNode extends Node {
+ private static final long serialVersionUID = 0L;
private String name;
private int offset;
+ public ArgAuxillaryNode() {
+ super();
+ }
+
public ArgAuxillaryNode(ISourcePosition position, String name, int offset) {
super(position);
this.name = name;
@@ -65,4 +73,16 @@ public Object accept(NodeVisitor visitor) {
public List<Node> childNodes() {
throw new UnsupportedOperationException("Not supported yet.");
}
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ super.writeExternal(out);
+ out.writeUTF(name);
+ out.writeInt(offset);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ super.readExternal(in);
+ name = in.readUTF();
+ offset = in.readInt();
+ }
}
@@ -31,6 +31,9 @@
***** END LICENSE BLOCK *****/
package org.jruby.ast;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.util.List;
import org.jruby.Ruby;
@@ -42,8 +45,13 @@
import org.jruby.runtime.builtin.IRubyObject;
public class ArgsCatNode extends Node {
- private final Node firstNode;
- private final Node secondNode;
+ private static final long serialVersionUID = 0L;
+ private Node firstNode;
+ private Node secondNode;
+
+ public ArgsCatNode() {
+ super();
+ }
public ArgsCatNode(ISourcePosition position, Node firstNode, Node secondNode) {
super(position);
@@ -89,4 +97,16 @@ public IRubyObject interpret(Ruby runtime, ThreadContext context, IRubyObject se
return RuntimeHelpers.ensureRubyArray(runtime, args).concat(secondArgs);
}
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ super.writeExternal(out);
+ out.writeObject(firstNode);
+ out.writeObject(secondNode);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ super.readExternal(in);
+ firstNode = (Node)in.readObject();
+ secondNode = (Node)in.readObject();
+ }
}
@@ -38,6 +38,11 @@
* @author enebo
*/
public class ArgsNoArgNode extends ArgsNode {
+ private static final long serialVersionUID = 0L;
+ public ArgsNoArgNode() {
+ super();
+ }
+
public ArgsNoArgNode(ISourcePosition position) {
super(position, null, null, null, null, null);
}
Oops, something went wrong.

0 comments on commit ee7db8e

Please sign in to comment.