Skip to content

Commit ae33064

Browse files
committed
Merge branch 'master' into truffle-head
Conflicts: truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
2 parents 1da4960 + 56ce58a commit ae33064

File tree

81 files changed

+323
-86
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+323
-86
lines changed

core/src/main/java/org/jruby/Ruby.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -907,12 +907,13 @@ public JITCompiler getJITCompiler() {
907907
return jitCompiler;
908908
}
909909

910-
public synchronized TruffleBridge getTruffleBridge() {
911-
if (truffleBridge == null) {
912-
truffleBridge = loadTruffleBridge();
910+
public TruffleBridge getTruffleBridge() {
911+
synchronized (truffleBridgeMutex) {
912+
if (truffleBridge == null) {
913+
truffleBridge = loadTruffleBridge();
914+
}
915+
return truffleBridge;
913916
}
914-
915-
return truffleBridge;
916917
}
917918

918919
private TruffleBridge loadTruffleBridge() {
@@ -943,9 +944,11 @@ private TruffleBridge loadTruffleBridge() {
943944
return truffleBridge;
944945
}
945946

946-
public synchronized void shutdownTruffleBridge() {
947-
if (truffleBridge != null) {
948-
truffleBridge.shutdown();
947+
public void shutdownTruffleBridge() {
948+
synchronized (truffleBridgeMutex) {
949+
if (truffleBridge != null) {
950+
truffleBridge.shutdown();
951+
}
949952
}
950953
}
951954

@@ -4912,6 +4915,7 @@ public FilenoUtil getFilenoUtil() {
49124915
private final JITCompiler jitCompiler;
49134916

49144917
private TruffleBridge truffleBridge;
4918+
private final Object truffleBridgeMutex = new Object();
49154919

49164920
// Note: this field and the following static initializer
49174921
// must be located be in this order!

core/src/main/java/org/jruby/ir/IRMethod.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@ public IRMethod(IRManager manager, IRScope lexicalParent, MethodDefNode defn, St
4141
}
4242
}
4343

44+
@Override
45+
public boolean hasBeenBuilt() {
46+
return defn == null;
47+
}
48+
4449
public synchronized InterpreterContext lazilyAcquireInterpreterContext() {
45-
if (defn != null) {
50+
if (!hasBeenBuilt()) {
4651
IRBuilder.topIRBuilder(getManager(), this).defineMethodInner(defn, getLexicalParent());
4752

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

5459
public synchronized BasicBlock[] prepareForInitialCompilation() {
55-
if (defn != null) lazilyAcquireInterpreterContext();
60+
if (!hasBeenBuilt()) lazilyAcquireInterpreterContext();
5661

5762
return super.prepareForInitialCompilation();
5863
}

core/src/main/java/org/jruby/ir/IRScope.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,13 @@ public boolean definesLocalVariable(Variable v) {
955955
return false;
956956
}
957957

958+
/**
959+
* For lazy scopes which IRBuild on demand we can ask this method whether it has been built yet...
960+
*/
961+
public boolean hasBeenBuilt() {
962+
return true;
963+
}
964+
958965
public InterpreterContext getInterpreterContext() {
959966
return interpreterContext;
960967
}

core/src/main/java/org/jruby/ir/instructions/BacktickInstr.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ public BacktickInstr(Variable result, Operand[] pieces) {
2222
super(Operation.BACKTICK_STRING, result, pieces);
2323
}
2424

25+
public Operand[] getPieces() {
26+
return getOperands();
27+
}
28+
2529
@Override
2630
public Instr clone(CloneInfo ii) {
2731
return new BacktickInstr(ii.getRenamedVariable(result), cloneOperands(ii));

core/src/main/java/org/jruby/ir/persistence/IRWriter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.jruby.RubyInstanceConfig;
44
import org.jruby.ir.IRClosure;
5+
import org.jruby.ir.IRMethod;
56
import org.jruby.ir.IRScope;
67
import org.jruby.ir.IRScriptBody;
78
import org.jruby.ir.instructions.Instr;
@@ -42,6 +43,11 @@ private static void persistScopeInstructions(IRWriterEncoder file, IRScope paren
4243
private static void persistScopeInstrs(IRWriterEncoder file, IRScope scope) {
4344
file.startEncodingScopeInstrs(scope);
4445

46+
// Currently methods are only lazy scopes so we need to build them if we decide to persist them.
47+
if (scope instanceof IRMethod && !scope.hasBeenBuilt()) {
48+
((IRMethod) scope).lazilyAcquireInterpreterContext();
49+
}
50+
4551
for (Instr instr: scope.getInterpreterContext().getInstructions()) {
4652
file.encode(instr);
4753
}

core/src/main/java/org/jruby/ir/persistence/IRWriterAnalzer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import java.util.HashMap;
1818
import java.util.Map;
19+
import org.jruby.util.ByteList;
1920

2021
/**
2122
*
@@ -35,6 +36,10 @@ public void encode(Instr instr) {
3536
}
3637
}
3738

39+
@Override
40+
public void encode(ByteList value) {
41+
}
42+
3843
@Override
3944
public void encode(String value) {
4045
}

core/src/main/java/org/jruby/ir/persistence/IRWriterEncoder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.jruby.ir.operands.Operand;
88
import org.jruby.ir.operands.OperandType;
99
import org.jruby.parser.StaticScope.Type;
10+
import org.jruby.util.ByteList;
1011

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

20+
public void encode(ByteList bytelist);
1921
public void encode(String value);
2022
public void encode(String[] values);
2123
public void encode(Instr value);

core/src/main/java/org/jruby/ir/persistence/IRWriterFile.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.nio.ByteBuffer;
2222
import java.util.HashMap;
2323
import java.util.Map;
24+
import org.jruby.util.ByteList;
2425

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

@@ -116,6 +117,16 @@ public void encode(double value) {
116117
buf.putDouble(value);
117118
}
118119

120+
@Override
121+
public void encode(ByteList value) {
122+
byte[] bytes = value.bytes();
123+
124+
encode(bytes.length);
125+
buf.put(bytes);
126+
// FIXME: Consider writing this out differently?
127+
encode(value.getEncoding().toString());
128+
}
129+
119130
@Override
120131
public void encode(String value) {
121132
encode(value.length());

core/src/main/java/org/jruby/ir/persistence/InstrEncoderMap.java

Lines changed: 65 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
package org.jruby.ir.persistence;
88

9+
import java.util.List;
10+
import org.jcodings.Encoding;
911
import org.jruby.RubyInstanceConfig;
1012
import org.jruby.ir.instructions.*;
1113
import org.jruby.ir.instructions.defined.RestoreErrorInfoInstr;
@@ -32,6 +34,7 @@ public void encode(Instr instr) {
3234

3335
switch(instr.getOperation()) {
3436
case ALIAS: encodeAliasInstr((AliasInstr) instr); break;
37+
case ARG_SCOPE_DEPTH: /* no state */ break;
3538
case ATTR_ASSIGN: encodeAttrAssignInstr((AttrAssignInstr) instr); break;
3639
case BEQ: encodeBEQInstr((BEQInstr) instr); break;
3740
case BINDING_LOAD: encodeLoadLocalVarInstr((LoadLocalVarInstr) instr); break;
@@ -43,13 +46,18 @@ public void encode(Instr instr) {
4346
case B_NIL: encodeBNilInstr((BNilInstr) instr); break;
4447
case B_TRUE: encodeBTrueInstr((BTrueInstr) instr); break;
4548
case B_UNDEF: encodeBUndefInstr((BUndefInstr) instr); break;
46-
case CALL: encodeCallBaseInstr((CallInstr) instr); break;
49+
case CALL: case CALL_1F: case CALL_1D: case CALL_1O: case CALL_1OB: case CALL_0O: case NORESULT_CALL_1O:
50+
encodeCallBaseInstr((CallInstr) instr); break;
4751
case CHECK_ARGS_ARRAY_ARITY: encodeCheckArgsArrayArityInstr((CheckArgsArrayArityInstr) instr); break;
4852
case CHECK_ARITY: encodeCheckArityInstr((CheckArityInstr) instr); break;
4953
case CLASS_VAR_MODULE: encodeGetClassVarContainerModuleInstr((GetClassVarContainerModuleInstr) instr); break;
50-
// case BUILD_COMPOUND_STRING: encodeBuildCompoundStringInstr((BuildCompoundStringInstr) instr); break;
51-
// case BUILD_DREGEXP: return encodeBuildDynRegExpInstr();
52-
// case BUILD_RANGE: return encodeBuildRangeInstr();
54+
case BACKTICK_STRING: encodeBacktickInstr((BacktickInstr) instr); break;
55+
case BUILD_COMPOUND_ARRAY: encodeBuildCompoundArrayInstr((BuildCompoundArrayInstr) instr); break;
56+
case BUILD_COMPOUND_STRING: encodeBuildCompoundStringInstr((BuildCompoundStringInstr) instr); break;
57+
case BUILD_DREGEXP: encodeBuildDynRegExpInstr((BuildDynRegExpInstr) instr); break;
58+
case BUILD_RANGE: encodeBuildRangeInstr((BuildRangeInstr) instr); break;
59+
case BUILD_SPLAT: encodeBuildSplatInstr((BuildSplatInstr) instr); break;
60+
case CHECK_FOR_LJE: encodeCheckForLJEInstr((CheckForLJEInstr) instr); break;
5361
case CONST_MISSING: encodeConstMissingInstr((ConstMissingInstr) instr); break;
5462
case COPY: encodeCopyInstr((CopyInstr) instr); break;
5563
case DEF_CLASS: encodeDefineClassInstr((DefineClassInstr) instr); break;
@@ -71,6 +79,8 @@ public void encode(Instr instr) {
7179
case LABEL: encodeLabelInstr((LabelInstr) instr); break;
7280
case LAMBDA: encodeBuildLambdaInstr((BuildLambdaInstr) instr); break;
7381
case LEXICAL_SEARCH_CONST: encodeLexicalSearchConstInstr((LexicalSearchConstInstr) instr); break;
82+
case LOAD_FRAME_CLOSURE: /* no state */ break;
83+
case LOAD_IMPLICIT_CLOSURE: /* no state */ break;
7484
case LINE_NUM: encodeLineNumberInstr((LineNumberInstr) instr); break;
7585
case MASGN_OPT: encodeOptArgMultipleAsgnInstr((OptArgMultipleAsgnInstr) instr); break;
7686
case MASGN_REQD: encodeReqdArgMultipleAsgnInstr((ReqdArgMultipleAsgnInstr) instr); break;
@@ -107,6 +117,7 @@ public void encode(Instr instr) {
107117
case RETURN: encodeReturnInstr((ReturnInstr) instr); break;
108118
case RUNTIME_HELPER: encodeRuntimeHelperCall((RuntimeHelperCall) instr); break;
109119
case SEARCH_CONST: encodeSearchConstInstr((SearchConstInstr) instr); break;
120+
case SET_CAPTURED_VAR: encodeSetCapturedVarInstr((SetCapturedVarInstr) instr); break;
110121
case CLASS_SUPER: encodeClassSuperInstr((ClassSuperInstr) instr); break;
111122
case INSTANCE_SUPER: encodeInstanceSuperInstr((InstanceSuperInstr) instr); break;
112123
case UNRESOLVED_SUPER: encodeUnresolvedSuperInstr((UnresolvedSuperInstr) instr); break;
@@ -131,9 +142,17 @@ private void encodeAttrAssignInstr(AttrAssignInstr instr) {
131142
Operand[] args = instr.getCallArgs();
132143

133144
e.encode(args.length);
145+
for(Operand arg: args) {
146+
e.encode(arg);
147+
}
148+
}
134149

135-
for (int i = 0; i < args.length; i++) {
136-
e.encode(args[i]);
150+
private void encodeBacktickInstr(BacktickInstr instr) {
151+
Operand[] pieces = instr.getPieces();
152+
153+
e.encode(pieces.length);
154+
for (Operand piece: pieces) {
155+
e.encode(piece);
137156
}
138157
}
139158

@@ -195,28 +214,32 @@ private void encodeCheckArityInstr(CheckArityInstr instr) {
195214
e.encode(instr.receivesKeywords);
196215
}
197216

217+
private void encodeCheckForLJEInstr(CheckForLJEInstr instr) {
218+
e.encode(instr.maybeLambda());
219+
}
220+
198221
private void encodeGetClassVarContainerModuleInstr(GetClassVarContainerModuleInstr instr) {
199222
e.encode(instr.getStartingScope());
200223
e.encode(instr.getObject());
201224
}
202225

203-
/**
226+
private void encodeBuildCompoundArrayInstr(BuildCompoundArrayInstr instr) {
227+
e.encode(instr.getAppendingArg());
228+
e.encode(instr.getAppendedArg());
229+
e.encode(instr.isArgsPush());
230+
}
231+
204232
private void encodeBuildCompoundStringInstr(BuildCompoundStringInstr instr) {
205-
Encoding encoding = compoundstring.getEncoding();
233+
Encoding encoding = instr.getEncoding();
206234

207-
if (encoding == null) {
208-
encoder.encode("");
209-
} else {
210-
encoder.encode(encoding.toString());
211-
}
212-
List<Operand> pieces = compoundstring.getPieces();
213-
encoder.encode(pieces.size());
235+
e.encode(encoding == null ? "" : encoding.toString());
236+
Operand[] pieces = instr.getPieces();
237+
e.encode(pieces.length);
214238

215239
for (Operand piece: pieces) {
216-
encode(piece);
240+
e.encode(piece);
217241
}
218242
}
219-
**/
220243

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

415+
private void encodeBuildDynRegExpInstr(BuildDynRegExpInstr instr) {
416+
Operand[] pieces = instr.getPieces();
417+
e.encode(pieces.length);
418+
419+
for (Operand piece: pieces) {
420+
e.encode(piece);
421+
}
422+
e.encode(instr.getOptions().toEmbeddedOptions());
423+
}
424+
425+
private void encodeBuildRangeInstr(BuildRangeInstr instr) {
426+
e.encode(instr.getBegin());
427+
e.encode(instr.getEnd());
428+
e.encode(instr.isExclusive());
429+
}
430+
431+
private void encodeBuildSplatInstr(BuildSplatInstr instr) {
432+
e.encode(instr.getArray());
433+
}
434+
392435
private void encodeRaiseArgumentErrorInstr(RaiseArgumentErrorInstr instr) {
393436
e.encode(instr.getRequired());
394437
e.encode(instr.getOpt());
@@ -459,6 +502,11 @@ private void encodeSearchConstInstr(SearchConstInstr instr) {
459502
e.encode(instr.isNoPrivateConsts());
460503
}
461504

505+
private void encodeSetCapturedVarInstr(SetCapturedVarInstr instr) {
506+
e.encode(instr.getMatch2Result());
507+
e.encode(instr.getVarName());
508+
}
509+
462510
private void encodeClassSuperInstr(ClassSuperInstr instr) {
463511
encodeCallBaseInstr(instr);
464512
}

core/src/main/java/org/jruby/ir/persistence/OperandEncoderMap.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public void encode(Operand operand) {
5555

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

58+
@Override public void FrozenString(FrozenString operand) { StringLiteral(operand); }
59+
5860
@Override public void GlobalVariable(GlobalVariable variable) { encoder.encode(variable.getName()); }
5961

6062
@Override public void Hash(Hash hash) {
@@ -100,7 +102,10 @@ public void encode(Operand operand) {
100102

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

103-
@Override public void StringLiteral(StringLiteral stringliteral) { encoder.encode(stringliteral.string); }
105+
@Override public void StringLiteral(StringLiteral stringliteral) {
106+
encoder.encode(stringliteral.getByteList());
107+
encoder.encode(stringliteral.getCodeRange());
108+
}
104109

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

0 commit comments

Comments
 (0)