Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head
Browse files Browse the repository at this point in the history
Conflicts:
	truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
  • Loading branch information
chrisseaton committed Mar 10, 2015
2 parents 1da4960 + 56ce58a commit ae33064
Show file tree
Hide file tree
Showing 81 changed files with 323 additions and 86 deletions.
20 changes: 12 additions & 8 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
Expand Up @@ -907,12 +907,13 @@ public JITCompiler getJITCompiler() {
return jitCompiler;
}

public synchronized TruffleBridge getTruffleBridge() {
if (truffleBridge == null) {
truffleBridge = loadTruffleBridge();
public TruffleBridge getTruffleBridge() {
synchronized (truffleBridgeMutex) {
if (truffleBridge == null) {
truffleBridge = loadTruffleBridge();
}
return truffleBridge;
}

return truffleBridge;
}

private TruffleBridge loadTruffleBridge() {
Expand Down Expand Up @@ -943,9 +944,11 @@ private TruffleBridge loadTruffleBridge() {
return truffleBridge;
}

public synchronized void shutdownTruffleBridge() {
if (truffleBridge != null) {
truffleBridge.shutdown();
public void shutdownTruffleBridge() {
synchronized (truffleBridgeMutex) {
if (truffleBridge != null) {
truffleBridge.shutdown();
}
}
}

Expand Down Expand Up @@ -4912,6 +4915,7 @@ public FilenoUtil getFilenoUtil() {
private final JITCompiler jitCompiler;

private TruffleBridge truffleBridge;
private final Object truffleBridgeMutex = new Object();

// Note: this field and the following static initializer
// must be located be in this order!
Expand Down
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
Expand Up @@ -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;
Expand All @@ -52,7 +57,7 @@ public synchronized InterpreterContext lazilyAcquireInterpreterContext() {
}

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

return super.prepareForInitialCompilation();
}
Expand Down
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
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public BacktickInstr(Variable result, Operand[] pieces) {
super(Operation.BACKTICK_STRING, result, pieces);
}

public Operand[] getPieces() {
return getOperands();
}

@Override
public Instr clone(CloneInfo ii) {
return new BacktickInstr(ii.getRenamedVariable(result), cloneOperands(ii));
Expand Down
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
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.util.HashMap;
import java.util.Map;
import org.jruby.util.ByteList;

/**
*
Expand All @@ -35,6 +36,10 @@ public void encode(Instr instr) {
}
}

@Override
public void encode(ByteList value) {
}

@Override
public void encode(String value) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.OperandType;
import org.jruby.parser.StaticScope.Type;
import org.jruby.util.ByteList;

/**
* Names are tough to find. Encodes values destined to be written to a persisted space.
Expand All @@ -16,6 +17,7 @@
*/
public interface IRWriterEncoder {

public void encode(ByteList bytelist);
public void encode(String value);
public void encode(String[] values);
public void encode(Instr value);
Expand Down
11 changes: 11 additions & 0 deletions core/src/main/java/org/jruby/ir/persistence/IRWriterFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
import org.jruby.util.ByteList;

// FIXME: Make into a base class at some point to play with different formats

Expand Down Expand Up @@ -116,6 +117,16 @@ public void encode(double value) {
buf.putDouble(value);
}

@Override
public void encode(ByteList value) {
byte[] bytes = value.bytes();

encode(bytes.length);
buf.put(bytes);
// FIXME: Consider writing this out differently?
encode(value.getEncoding().toString());
}

@Override
public void encode(String value) {
encode(value.length());
Expand Down
82 changes: 65 additions & 17 deletions core/src/main/java/org/jruby/ir/persistence/InstrEncoderMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,6 +34,7 @@ public void encode(Instr instr) {

switch(instr.getOperation()) {
case ALIAS: encodeAliasInstr((AliasInstr) instr); break;
case ARG_SCOPE_DEPTH: /* no state */ break;
case ATTR_ASSIGN: encodeAttrAssignInstr((AttrAssignInstr) instr); break;
case BEQ: encodeBEQInstr((BEQInstr) instr); break;
case BINDING_LOAD: encodeLoadLocalVarInstr((LoadLocalVarInstr) instr); break;
Expand All @@ -43,13 +46,18 @@ 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 BACKTICK_STRING: encodeBacktickInstr((BacktickInstr) instr); break;
case BUILD_COMPOUND_ARRAY: encodeBuildCompoundArrayInstr((BuildCompoundArrayInstr) instr); break;
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 CHECK_FOR_LJE: encodeCheckForLJEInstr((CheckForLJEInstr) instr); break;
case CONST_MISSING: encodeConstMissingInstr((ConstMissingInstr) instr); break;
case COPY: encodeCopyInstr((CopyInstr) instr); break;
case DEF_CLASS: encodeDefineClassInstr((DefineClassInstr) instr); break;
Expand All @@ -71,6 +79,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;
Expand Down Expand Up @@ -107,6 +117,7 @@ public void encode(Instr instr) {
case RETURN: encodeReturnInstr((ReturnInstr) instr); break;
case RUNTIME_HELPER: encodeRuntimeHelperCall((RuntimeHelperCall) instr); break;
case SEARCH_CONST: encodeSearchConstInstr((SearchConstInstr) instr); break;
case SET_CAPTURED_VAR: encodeSetCapturedVarInstr((SetCapturedVarInstr) instr); break;
case CLASS_SUPER: encodeClassSuperInstr((ClassSuperInstr) instr); break;
case INSTANCE_SUPER: encodeInstanceSuperInstr((InstanceSuperInstr) instr); break;
case UNRESOLVED_SUPER: encodeUnresolvedSuperInstr((UnresolvedSuperInstr) instr); break;
Expand All @@ -131,9 +142,17 @@ private void encodeAttrAssignInstr(AttrAssignInstr instr) {
Operand[] args = instr.getCallArgs();

e.encode(args.length);
for(Operand arg: args) {
e.encode(arg);
}
}

for (int i = 0; i < args.length; i++) {
e.encode(args[i]);
private void encodeBacktickInstr(BacktickInstr instr) {
Operand[] pieces = instr.getPieces();

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

Expand Down Expand Up @@ -195,28 +214,32 @@ private void encodeCheckArityInstr(CheckArityInstr instr) {
e.encode(instr.receivesKeywords);
}

private void encodeCheckForLJEInstr(CheckForLJEInstr instr) {
e.encode(instr.maybeLambda());
}

private void encodeGetClassVarContainerModuleInstr(GetClassVarContainerModuleInstr instr) {
e.encode(instr.getStartingScope());
e.encode(instr.getObject());
}

/**
private void encodeBuildCompoundArrayInstr(BuildCompoundArrayInstr instr) {
e.encode(instr.getAppendingArg());
e.encode(instr.getAppendedArg());
e.encode(instr.isArgsPush());
}

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());
Expand Down Expand Up @@ -389,6 +412,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());
Expand Down Expand Up @@ -459,6 +502,11 @@ private void encodeSearchConstInstr(SearchConstInstr instr) {
e.encode(instr.isNoPrivateConsts());
}

private void encodeSetCapturedVarInstr(SetCapturedVarInstr instr) {
e.encode(instr.getMatch2Result());
e.encode(instr.getVarName());
}

private void encodeClassSuperInstr(ClassSuperInstr instr) {
encodeCallBaseInstr(instr);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public void encode(Operand operand) {

@Override public void Float(Float flote) { encoder.encode(flote.value); }

@Override public void FrozenString(FrozenString operand) { StringLiteral(operand); }

@Override public void GlobalVariable(GlobalVariable variable) { encoder.encode(variable.getName()); }

@Override public void Hash(Hash hash) {
Expand Down Expand Up @@ -100,7 +102,10 @@ public void encode(Operand operand) {

@Override public void StandardError(StandardError standarderror) {} // No data

@Override public void StringLiteral(StringLiteral stringliteral) { encoder.encode(stringliteral.string); }
@Override public void StringLiteral(StringLiteral stringliteral) {
encoder.encode(stringliteral.getByteList());
encoder.encode(stringliteral.getCodeRange());
}

@Override public void SValue(SValue svalue) { encode(svalue.getArray()); }

Expand Down
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/optparse.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../stdlib/optparse'
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/optparse/ac.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../stdlib/optparse/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/optparse/date.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../stdlib/optparse/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/optparse/shellwords.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../stdlib/optparse/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/optparse/time.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../stdlib/optparse/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/optparse/uri.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../stdlib/optparse/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/optparse/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../stdlib/optparse/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/test/unit.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../stdlib/test/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/test/unit/assertion-failed-error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../../stdlib/test/unit/' + File.basename(__FILE__)
2 changes: 2 additions & 0 deletions lib/ruby/truffle/mri/test/unit/assertions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require_relative '../../../../stdlib/test/unit/' + File.basename(__FILE__)

2 changes: 2 additions & 0 deletions lib/ruby/truffle/mri/test/unit/attribute-matcher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require_relative '../../../../stdlib/test/unit/' + File.basename(__FILE__)

2 changes: 2 additions & 0 deletions lib/ruby/truffle/mri/test/unit/attribute.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require_relative '../../../../stdlib/test/unit/' + File.basename(__FILE__)

2 changes: 2 additions & 0 deletions lib/ruby/truffle/mri/test/unit/autorunner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require_relative '../../../../stdlib/test/unit/' + File.basename(__FILE__)

2 changes: 2 additions & 0 deletions lib/ruby/truffle/mri/test/unit/code-snippet-fetcher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require_relative '../../../../stdlib/test/unit/' + File.basename(__FILE__)

2 changes: 2 additions & 0 deletions lib/ruby/truffle/mri/test/unit/collector.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require_relative '../../../../stdlib/test/unit/' + File.basename(__FILE__)

2 changes: 2 additions & 0 deletions lib/ruby/truffle/mri/test/unit/collector/descendant.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require_relative '../../../../../stdlib/test/unit/collector/' + File.basename(__FILE__)

2 changes: 2 additions & 0 deletions lib/ruby/truffle/mri/test/unit/collector/dir.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require_relative '../../../../../stdlib/test/unit/collector/' + File.basename(__FILE__)

2 changes: 2 additions & 0 deletions