Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: d0c8c5585c63
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 50506f18bb6a
Choose a head ref
  • 5 commits
  • 4 files changed
  • 1 contributor

Commits on Mar 9, 2015

  1. Copy the full SHA
    3e1c573 View commit details
  2. Copy the full SHA
    b792773 View commit details
  3. Copy the full SHA
    9404de4 View commit details
  4. Copy the full SHA
    0a7a1db View commit details
  5. Copy the full SHA
    50506f1 View commit details
9 changes: 7 additions & 2 deletions core/src/main/java/org/jruby/ir/IRMethod.java
Original file line number Diff line number Diff line change
@@ -41,8 +41,13 @@ public IRMethod(IRManager manager, IRScope lexicalParent, MethodDefNode defn, St
}
}

@Override
public boolean hasBeenBuilt() {
return defn == null;
}

public synchronized InterpreterContext lazilyAcquireInterpreterContext() {
if (defn != null) {
if (!hasBeenBuilt()) {
IRBuilder.topIRBuilder(getManager(), this).defineMethodInner(defn, getLexicalParent());

defn = null;
@@ -52,7 +57,7 @@ public synchronized InterpreterContext lazilyAcquireInterpreterContext() {
}

public synchronized BasicBlock[] prepareForInitialCompilation() {
if (defn != null) lazilyAcquireInterpreterContext();
if (!hasBeenBuilt()) lazilyAcquireInterpreterContext();

return super.prepareForInitialCompilation();
}
7 changes: 7 additions & 0 deletions core/src/main/java/org/jruby/ir/IRScope.java
Original file line number Diff line number Diff line change
@@ -955,6 +955,13 @@ public boolean definesLocalVariable(Variable v) {
return false;
}

/**
* For lazy scopes which IRBuild on demand we can ask this method whether it has been built yet...
*/
public boolean hasBeenBuilt() {
return true;
}

public InterpreterContext getInterpreterContext() {
return interpreterContext;
}
6 changes: 6 additions & 0 deletions core/src/main/java/org/jruby/ir/persistence/IRWriter.java
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

import org.jruby.RubyInstanceConfig;
import org.jruby.ir.IRClosure;
import org.jruby.ir.IRMethod;
import org.jruby.ir.IRScope;
import org.jruby.ir.IRScriptBody;
import org.jruby.ir.instructions.Instr;
@@ -42,6 +43,11 @@ private static void persistScopeInstructions(IRWriterEncoder file, IRScope paren
private static void persistScopeInstrs(IRWriterEncoder file, IRScope scope) {
file.startEncodingScopeInstrs(scope);

// Currently methods are only lazy scopes so we need to build them if we decide to persist them.
if (scope instanceof IRMethod && !scope.hasBeenBuilt()) {
((IRMethod) scope).lazilyAcquireInterpreterContext();
}

for (Instr instr: scope.getInterpreterContext().getInstructions()) {
file.encode(instr);
}
50 changes: 35 additions & 15 deletions core/src/main/java/org/jruby/ir/persistence/InstrEncoderMap.java
Original file line number Diff line number Diff line change
@@ -6,6 +6,8 @@

package org.jruby.ir.persistence;

import java.util.List;
import org.jcodings.Encoding;
import org.jruby.RubyInstanceConfig;
import org.jruby.ir.instructions.*;
import org.jruby.ir.instructions.defined.RestoreErrorInfoInstr;
@@ -43,13 +45,15 @@ public void encode(Instr instr) {
case B_NIL: encodeBNilInstr((BNilInstr) instr); break;
case B_TRUE: encodeBTrueInstr((BTrueInstr) instr); break;
case B_UNDEF: encodeBUndefInstr((BUndefInstr) instr); break;
case CALL: encodeCallBaseInstr((CallInstr) instr); break;
case CALL: case CALL_1F: case CALL_1D: case CALL_1O: case CALL_1OB: case CALL_0O: case NORESULT_CALL_1O:
encodeCallBaseInstr((CallInstr) instr); break;
case CHECK_ARGS_ARRAY_ARITY: encodeCheckArgsArrayArityInstr((CheckArgsArrayArityInstr) instr); break;
case CHECK_ARITY: encodeCheckArityInstr((CheckArityInstr) instr); break;
case CLASS_VAR_MODULE: encodeGetClassVarContainerModuleInstr((GetClassVarContainerModuleInstr) instr); break;
// case BUILD_COMPOUND_STRING: encodeBuildCompoundStringInstr((BuildCompoundStringInstr) instr); break;
// case BUILD_DREGEXP: return encodeBuildDynRegExpInstr();
// case BUILD_RANGE: return encodeBuildRangeInstr();
case BUILD_COMPOUND_STRING: encodeBuildCompoundStringInstr((BuildCompoundStringInstr) instr); break;
case BUILD_DREGEXP: encodeBuildDynRegExpInstr((BuildDynRegExpInstr) instr); break;
case BUILD_RANGE: encodeBuildRangeInstr((BuildRangeInstr) instr); break;
case BUILD_SPLAT: encodeBuildSplatInstr((BuildSplatInstr) instr); break;
case CONST_MISSING: encodeConstMissingInstr((ConstMissingInstr) instr); break;
case COPY: encodeCopyInstr((CopyInstr) instr); break;
case DEF_CLASS: encodeDefineClassInstr((DefineClassInstr) instr); break;
@@ -71,6 +75,8 @@ public void encode(Instr instr) {
case LABEL: encodeLabelInstr((LabelInstr) instr); break;
case LAMBDA: encodeBuildLambdaInstr((BuildLambdaInstr) instr); break;
case LEXICAL_SEARCH_CONST: encodeLexicalSearchConstInstr((LexicalSearchConstInstr) instr); break;
case LOAD_FRAME_CLOSURE: /* no state */ break;
case LOAD_IMPLICIT_CLOSURE: /* no state */ break;
case LINE_NUM: encodeLineNumberInstr((LineNumberInstr) instr); break;
case MASGN_OPT: encodeOptArgMultipleAsgnInstr((OptArgMultipleAsgnInstr) instr); break;
case MASGN_REQD: encodeReqdArgMultipleAsgnInstr((ReqdArgMultipleAsgnInstr) instr); break;
@@ -200,23 +206,17 @@ private void encodeGetClassVarContainerModuleInstr(GetClassVarContainerModuleIns
e.encode(instr.getObject());
}

/**
private void encodeBuildCompoundStringInstr(BuildCompoundStringInstr instr) {
Encoding encoding = compoundstring.getEncoding();
Encoding encoding = instr.getEncoding();

if (encoding == null) {
encoder.encode("");
} else {
encoder.encode(encoding.toString());
}
List<Operand> pieces = compoundstring.getPieces();
encoder.encode(pieces.size());
e.encode(encoding == null ? "" : encoding.toString());
Operand[] pieces = instr.getPieces();
e.encode(pieces.length);

for (Operand piece: pieces) {
encode(piece);
e.encode(piece);
}
}
**/

private void encodeConstMissingInstr(ConstMissingInstr instr) {
e.encode(instr.getReceiver());
@@ -389,6 +389,26 @@ private void encodePutGlobalVarInstr(PutGlobalVarInstr instr) {
e.encode(instr.getValue());
}

private void encodeBuildDynRegExpInstr(BuildDynRegExpInstr instr) {
Operand[] pieces = instr.getPieces();
e.encode(pieces.length);

for (Operand piece: pieces) {
e.encode(piece);
}
e.encode(instr.getOptions().toEmbeddedOptions());
}

private void encodeBuildRangeInstr(BuildRangeInstr instr) {
e.encode(instr.getBegin());
e.encode(instr.getEnd());
e.encode(instr.isExclusive());
}

private void encodeBuildSplatInstr(BuildSplatInstr instr) {
e.encode(instr.getArray());
}

private void encodeRaiseArgumentErrorInstr(RaiseArgumentErrorInstr instr) {
e.encode(instr.getRequired());
e.encode(instr.getOpt());