Skip to content

Commit

Permalink
Pencil in simple implementation of ModuleVersionGuardInstr
Browse files Browse the repository at this point in the history
  • Loading branch information
enebo committed Jan 24, 2017
1 parent 92be326 commit e0209c9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Expand Up @@ -3,6 +3,7 @@
import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.runtime.IRDeoptimization;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
Expand Down Expand Up @@ -58,4 +59,13 @@ private boolean versionMatches(ThreadContext context, StaticScope currScope, Dyn
public void visit(IRVisitor visitor) {
visitor.ModuleVersionGuardInstr(this);
}

@Override
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) {
if (!versionMatches(context, currScope, currDynScope, self, temp)) {
throw new IRDeoptimization(ipc);
}

return context.nil; /* not used */
}
}
19 changes: 19 additions & 0 deletions core/src/main/java/org/jruby/ir/runtime/IRDeoptimization.java
@@ -0,0 +1,19 @@
package org.jruby.ir.runtime;

/**
* When we want to back off from optimized IR back to safe IR we will throw
* this exception.
*/
public class IRDeoptimization extends RuntimeException {
private final int ipc;

public IRDeoptimization(int ipc) {
super();

this.ipc = ipc;
}

public int getIPC() {
return ipc;
}
}

0 comments on commit e0209c9

Please sign in to comment.