Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Tweaks here and there to make procs serializable.

Caveats:

* Only interpreted procs will serialize, since compiled/jitted don't safe their bytecode.
* Wherever a class is referenced (object metaclass, const scoping) the name is stored and looked up on the other side.
* Assumes we're loading into the one global org.jruby.Ruby instance; this could be made Thread-local as well.
  • Loading branch information...
commit 3f63adc276933e708e8c82853174eb2a32340c73 1 parent ee7db8e
@headius headius authored
View
11 src/org/jruby/RubyBasicObject.java
@@ -27,6 +27,7 @@
***** END LICENSE BLOCK *****/
package org.jruby;
+import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@@ -1897,4 +1898,14 @@ private void callFinalizer(IRubyObject finalizer) {
finalizer, "call", id);
}
}
+
+ private void writeObject(java.io.ObjectOutputStream out) throws IOException {
+ out.defaultWriteObject();
+ out.writeUTF(metaClass.getName());
+ }
+
+ private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
+ in.defaultReadObject();
+ metaClass = (RubyClass)Ruby.getGlobalRuntime().getClassFromPath(in.readUTF());
+ }
}
View
17 src/org/jruby/parser/StaticScope.java
@@ -483,4 +483,21 @@ public String toString() {
return buf.toString();
}
+
+ private void writeObject(java.io.ObjectOutputStream out) throws IOException {
+ out.defaultWriteObject();
+ if (cref != null) {
+ out.writeObject(cref.getName());
+ } else {
+ out.writeObject(null);
+ }
+ }
+
+ private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
+ in.defaultReadObject();
+ Object crefName = in.readObject();
+ if (crefName != null) {
+ cref = Ruby.getGlobalRuntime().getClassFromPath(crefName.toString());
+ }
+ }
}
View
5 src/org/jruby/runtime/Binding.java
@@ -32,6 +32,7 @@
***** END LICENSE BLOCK *****/
package org.jruby.runtime;
+import java.io.Serializable;
import org.jruby.RubyModule;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.builtin.IRubyObject;
@@ -39,13 +40,13 @@
/**
* Internal live representation of a block ({...} or do ... end).
*/
-public class Binding {
+public class Binding implements Serializable {
/**
* frame of method which defined this block
*/
private final Frame frame;
- private final RubyModule klass;
+ private transient final RubyModule klass;
private Visibility visibility;
/**
View
3  src/org/jruby/runtime/Block.java
@@ -41,6 +41,7 @@
package org.jruby.runtime;
+import java.io.Serializable;
import org.jruby.RubyModule;
import org.jruby.RubyProc;
import org.jruby.runtime.builtin.IRubyObject;
@@ -48,7 +49,7 @@
/**
* Internal live representation of a block ({...} or do ... end).
*/
-public final class Block {
+public final class Block implements Serializable {
public enum Type { NORMAL, PROC, LAMBDA, THREAD }
/**
View
3  src/org/jruby/runtime/BlockBody.java
@@ -41,6 +41,7 @@
package org.jruby.runtime;
+import java.io.Serializable;
import org.jruby.RubyArray;
import org.jruby.RubyModule;
import org.jruby.ast.IterNode;
@@ -53,7 +54,7 @@
/**
* The executable body portion of a closure.
*/
-public abstract class BlockBody {
+public abstract class BlockBody implements Serializable {
// FIXME: Maybe not best place, but move it to a good home
public static final int ZERO_ARGS = 0;
public static final int MULTIPLE_ASSIGNMENT = 1;
View
3  src/org/jruby/runtime/DynamicScope.java
@@ -8,6 +8,7 @@
package org.jruby.runtime;
+import java.io.Serializable;
import org.jruby.Ruby;
import org.jruby.parser.BlockStaticScope;
import org.jruby.runtime.scope.ManyVarsDynamicScope;
@@ -21,7 +22,7 @@
import org.jruby.runtime.scope.ThreeVarDynamicScope;
import org.jruby.runtime.scope.TwoVarDynamicScope;
-public abstract class DynamicScope {
+public abstract class DynamicScope implements Serializable {
// Static scoping information for this scope
protected final StaticScope staticScope;
View
5 src/org/jruby/runtime/Frame.java
@@ -32,6 +32,7 @@
***** END LICENSE BLOCK *****/
package org.jruby.runtime;
+import java.io.Serializable;
import org.jruby.RubyModule;
import org.jruby.runtime.builtin.IRubyObject;
@@ -60,9 +61,9 @@
*
* @see ThreadContext
*/
-public final class Frame {
+public final class Frame implements Serializable {
/** The class against which this call is executing. */
- private RubyModule klazz;
+ private transient RubyModule klazz;
/** The 'self' for this frame. */
private IRubyObject self;
View
3  src/org/jruby/runtime/InterpretedBlock.java
@@ -32,6 +32,7 @@
***** END LICENSE BLOCK *****/
package org.jruby.runtime;
+import java.io.Serializable;
import org.jruby.Ruby;
import org.jruby.RubyModule;
import org.jruby.ast.IterNode;
@@ -76,7 +77,7 @@
*
* @see SharedScopeBlock, CompiledBlock
*/
-public class InterpretedBlock extends BlockBody {
+public class InterpretedBlock extends BlockBody implements Serializable {
/** This block has no arguments at all (simple secondary optimization @see assignerFor for an
* explanation).
*/
View
3  src/org/jruby/runtime/assigner/Assigner.java
@@ -29,6 +29,7 @@
package org.jruby.runtime.assigner;
+import java.io.Serializable;
import org.jruby.Ruby;
import org.jruby.ast.util.ArgsUtil;
import org.jruby.runtime.Block;
@@ -50,7 +51,7 @@
* There is also some logic about expanded/non-expanded arguments. This refers to
* ParserSupport.new_yield and YieldNode expanded attribute.
*/
-public abstract class Assigner {
+public abstract class Assigner implements Serializable {
public abstract void assign(Ruby runtime, ThreadContext context, IRubyObject self, Block block);
public abstract void assign(Ruby runtime, ThreadContext context, IRubyObject self, IRubyObject value1,
Please sign in to comment.
Something went wrong with that request. Please try again.