Skip to content

Commit 9bc3439

Browse files
committed
Merge branch 'master' into truffle-head
Conflicts: truffle/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java truffle/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
2 parents 76cab7b + 2238abf commit 9bc3439

File tree

84 files changed

+1321
-687
lines changed

Some content is hidden

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

84 files changed

+1321
-687
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,12 @@ public IRubyObject append(ThreadContext context, IRubyObject obj) {
6565
} else {
6666
paths = context.runtime.newArray(obj).toJavaArray();
6767
}
68-
69-
boolean is1_8 = context.getRuntime().is1_8();
68+
7069
for (IRubyObject path: paths) {
7170
try {
7271
URL url = getURL(path.convertToString().toString());
7372
if (url.getProtocol().equals("file")) {
74-
path = is1_8 ? RubyFile.expand_path(context, null, new IRubyObject[]{ path })
75-
: RubyFile.expand_path19(context, null, new IRubyObject[]{ path });
73+
path = RubyFile.expand_path19(context, null, new IRubyObject[]{ path });
7674
url = getURL(path.convertToString().toString());
7775
}
7876
getRuntime().getJRubyClassLoader().addURL(url);

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,20 +175,15 @@ public static Encoding areCompatible(CodeRangeable obj1, CodeRangeable obj2) {
175175

176176
if (obj2.getByteList().getRealSize() == 0) return enc1;
177177
if (obj1.getByteList().getRealSize() == 0) {
178-
return enc1.isAsciiCompatible() && obj2 instanceof RubyString &&
179-
((RubyString) obj2).isAsciiOnly() ? enc1 : enc2;
178+
return enc1.isAsciiCompatible() && StringSupport.isAsciiOnly(obj2) ? enc1 : enc2;
180179
}
181180

182181
if (!enc1.isAsciiCompatible() || !enc2.isAsciiCompatible()) return null;
183182

184183
int cr1 = obj1.scanForCodeRange();
185-
if (obj2 instanceof RubyString) {
186-
int cr2 = obj2.scanForCodeRange();
187-
return areCompatible(enc1, cr1, enc2, cr2);
188-
}
189-
if (cr1 == StringSupport.CR_7BIT) return enc2;
184+
int cr2 = obj2.scanForCodeRange();
190185

191-
return null;
186+
return areCompatible(enc1, cr1, enc2, cr2);
192187
}
193188

194189
public static Encoding areCompatible(Encoding enc1, Encoding enc2) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public final boolean isCodeRangeAsciiOnly() {
217217

218218
// rb_enc_str_asciionly_p
219219
public final boolean isAsciiOnly() {
220-
return value.getEncoding().isAsciiCompatible() && scanForCodeRange() == CR_7BIT;
220+
return StringSupport.isAsciiOnly(this);
221221
}
222222

223223
@Override

core/src/main/java/org/jruby/internal/runtime/methods/InterpretedIRMethod.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,7 @@ protected void doDebug() {
230230
ensureInstrsReady();
231231
LOG.info("Executing '" + method.getName() + "'");
232232
if (!displayedCFG) {
233-
CFG cfg = method.getCFG();
234-
LOG.info("Graph:\n" + cfg.toStringGraph());
235-
LOG.info("CFG:\n" + cfg.toStringInstrs());
233+
LOG.info(method.debugOutput());
236234
displayedCFG = true;
237235
}
238236
}

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,10 @@ public boolean canReceiveNonlocalReturns() {
441441
}
442442

443443
public CFG buildCFG() {
444+
if (getCFG() != null) {
445+
return getCFG();
446+
}
447+
444448
CFG newCFG = new CFG(this);
445449
newCFG.build(getInstrs());
446450
// Clear out instruction list after CFG has been built.
@@ -641,9 +645,7 @@ private void setupLinearization() {
641645
depends(linearization());
642646
} catch (RuntimeException e) {
643647
LOG.error("Error linearizing cfg: ", e);
644-
CFG c = cfg();
645-
LOG.error("\nGraph:\n" + c.toStringGraph());
646-
LOG.error("\nInstructions:\n" + c.toStringInstrs());
648+
LOG.error(this.debugOutput());
647649
throw e;
648650
}
649651
}
@@ -764,6 +766,16 @@ public String toString() {
764766
return getScopeType() + " " + getName() + "[" + getFileName() + ":" + getLineNumber() + "]";
765767
}
766768

769+
public String debugOutput() {
770+
if (this.cfg == null) {
771+
return "Instructions:\n" + this.toStringInstrs();
772+
} else {
773+
return
774+
"\nCFG:\n" + this.cfg.toStringGraph() +
775+
"\nInstructions:\n" + this.cfg.toStringInstrs();
776+
}
777+
}
778+
767779
public String toStringInstrs() {
768780
StringBuilder b = new StringBuilder();
769781

core/src/main/java/org/jruby/ir/interpreter/Interpreter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,7 @@ private static BeginEndInterpreterContext prepareIC(ThreadContext context, Dynam
235235
BeginEndInterpreterContext ic = (BeginEndInterpreterContext) script.prepareForInterpretation();
236236

237237
if (IRRuntimeHelpers.isDebug()) {
238-
LOG.info("Graph:\n" + script.cfg().toStringGraph());
239-
LOG.info("CFG:\n" + script.cfg().toStringInstrs());
238+
LOG.info(script.debugOutput());
240239
}
241240

242241
return ic;

core/src/main/java/org/jruby/ir/interpreter/InterpreterContext.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,16 @@ public String toString() {
161161
buf.append(fileName).append(':').append(lineNumber);
162162
if (name != null) buf.append(' ').append(name);
163163

164-
buf.append("\nCFG:\n").append(cfg.toStringInstrs());
164+
if (cfg != null) {
165+
buf.append("\nCFG:\n").append(cfg.toStringInstrs());
166+
} else {
167+
int i = 0;
168+
for (Instr instr : instructions) {
169+
if (i > 0) buf.append("\n");
170+
buf.append(" ").append(i).append('\t').append(instr);
171+
i++;
172+
}
173+
}
165174

166175
return buf.toString();
167176
}

core/src/main/java/org/jruby/runtime/InterpretedIRBlockBody.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ public InterpretedIRBlockBody(IRClosure closure, Signature signature) {
2929
public InterpreterContext ensureInstrsReady() {
3030
if (IRRuntimeHelpers.isDebug() && !displayedCFG) {
3131
LOG.info("Executing '" + closure + "' (pushScope=" + pushScope + ", reuseParentScope=" + reuseParentScope);
32-
CFG cfg = closure.getCFG();
33-
LOG.info("Graph:\n" + cfg.toStringGraph());
34-
LOG.info("CFG:\n" + cfg.toStringInstrs());
32+
LOG.info(closure.debugOutput());
3533
displayedCFG = true;
3634
}
3735
// Always prepared in the context of parent scope -- so a null value here is a bug.

core/src/main/java/org/jruby/runtime/load/LibrarySearcher.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ private FoundLibrary findResourceLibrary(String baseName, String suffix) {
147147

148148
// FIXME: to_path should not be called n times it should only be once and that means a cache which would
149149
// also reduce all this casting and/or string creates.
150+
// (mkristian) would it make sense to turn $LOAD_PATH into something like RubyClassPathVariable where we could cache
151+
// the Strings ?
150152
private String getPath(IRubyObject loadPathEntry) {
151-
if (runtime.is1_8()) return loadPathEntry.convertToString().asJavaString();
152-
153153
return RubyFile.get_path(runtime.getCurrentContext(), loadPathEntry).asJavaString();
154154
}
155155

core/src/main/java/org/jruby/util/ByteListHolder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
public interface ByteListHolder {
3232
public ByteList getByteList();
33+
public void modify();
3334
public void modify(int length);
3435
public Encoding checkEncoding(ByteListHolder other);
3536
}

core/src/main/java/org/jruby/util/IdUtil.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,22 @@ public final class IdUtil {
3333
/**
3434
* rb_is_const_id and is_const_id
3535
*/
36-
public static boolean isConstant(String id) {
37-
return Character.isUpperCase(id.charAt(0));
36+
public static boolean isConstant(String id) {
37+
return Character.isUpperCase(id.charAt(0));
3838
}
3939

4040
/**
4141
* rb_is_class_id and is_class_id
4242
*/
43-
public static boolean isClassVariable(String id) {
44-
return id.length()>1 && id.charAt(0) == '@' && id.charAt(1) == '@';
43+
public static boolean isClassVariable(String id) {
44+
return id.length() > 1 && id.charAt(0) == '@' && id.charAt(1) == '@';
4545
}
4646

4747
/**
4848
* rb_is_instance_id and is_instance_id
4949
*/
50-
public static boolean isInstanceVariable(String id) {
51-
return id.length()>0 && id.charAt(0) == '@' && (id.length() < 2 || id.charAt(1) != '@');
50+
public static boolean isInstanceVariable(String id) {
51+
return id.length() > 0 && id.charAt(0) == '@' && (id.length() < 2 || id.charAt(1) != '@');
5252
}
5353

5454
/**
@@ -65,8 +65,8 @@ public static boolean isPredicate(String id) {
6565
/**
6666
* rb_is_local_id and is_local_id
6767
*/
68-
public static boolean isLocal(String id) {
69-
return !isGlobal(id) && !isClassVariable(id) && !isInstanceVariable(id) && !isConstant(id) && !isPredicate(id) && !isSpecial(id);
68+
public static boolean isLocal(String id) {
69+
return !isGlobal(id) && !isClassVariable(id) && !isInstanceVariable(id) && !isConstant(id) && !isPredicate(id) && !isSpecial(id);
7070
}
7171

7272
/**
@@ -77,9 +77,9 @@ public static boolean isSpecial(String id) {
7777
return id.startsWith("%");
7878
}
7979

80-
public static boolean isAttrSet(String id) {
81-
return id.endsWith("=");
82-
}
80+
public static boolean isAttrSet(String id) {
81+
return id.endsWith("=");
82+
}
8383

8484
public static boolean isValidConstantName(String id) {
8585
char c;

core/src/main/java/org/jruby/util/StringSupport.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,4 +1275,8 @@ public static void replaceInternal19(int beg, int len, CodeRangeable source, Cod
12751275
cr = CodeRangeSupport.codeRangeAnd(cr, repl.getCodeRange());
12761276
if (cr != CR_BROKEN) source.setCodeRange(cr);
12771277
}
1278+
1279+
public static boolean isAsciiOnly(CodeRangeable string) {
1280+
return string.getByteList().getEncoding().isAsciiCompatible() && string.scanForCodeRange() == CR_7BIT;
1281+
}
12781282
}

core/src/main/java/org/jruby/util/io/EncodingUtils.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
import org.jruby.runtime.encoding.EncodingCapable;
3939
import org.jruby.runtime.encoding.EncodingService;
4040
import org.jruby.util.ByteList;
41+
import org.jruby.util.ByteListHolder;
4142
import org.jruby.util.CodeRangeSupport;
43+
import org.jruby.util.CodeRangeable;
4244
import org.jruby.util.StringSupport;
4345
import org.jruby.util.TypeConverter;
4446

@@ -1461,7 +1463,7 @@ public static void rbStrBufCat(Ruby runtime, RubyString str, ByteList ptr) {
14611463
// negative length check here, we shouldn't need
14621464
strBufCat(runtime, str, ptr);
14631465
}
1464-
public static void rbStrBufCat(Ruby runtime, RubyString str, byte[] ptrBytes, int ptr, int len) {
1466+
public static void rbStrBufCat(Ruby runtime, ByteListHolder str, byte[] ptrBytes, int ptr, int len) {
14651467
if (len == 0) return;
14661468
// negative length check here, we shouldn't need
14671469
strBufCat(runtime, str, ptrBytes, ptr, len);
@@ -1476,7 +1478,7 @@ public static void rbStrBufCat(Ruby runtime, ByteList str, byte[] ptrBytes, int
14761478
public static void strBufCat(Ruby runtime, RubyString str, ByteList ptr) {
14771479
strBufCat(runtime, str, ptr.getUnsafeBytes(), ptr.getBegin(), ptr.getRealSize());
14781480
}
1479-
public static void strBufCat(Ruby runtime, RubyString str, byte[] ptrBytes, int ptr, int len) {
1481+
public static void strBufCat(Ruby runtime, ByteListHolder str, byte[] ptrBytes, int ptr, int len) {
14801482
str.modify();
14811483
strBufCat(str.getByteList(), ptrBytes, ptr, len);
14821484
}
@@ -1508,16 +1510,16 @@ public static void encStrBufCat(Ruby runtime, RubyString str, byte[] ptrBytes, i
15081510
}
15091511

15101512
// rb_enc_cr_str_buf_cat
1511-
public static void encCrStrBufCat(Ruby runtime, RubyString str, ByteList ptr, Encoding ptrEnc, int ptr_cr, int[] ptr_cr_ret) {
1513+
public static void encCrStrBufCat(Ruby runtime, CodeRangeable str, ByteList ptr, Encoding ptrEnc, int ptr_cr, int[] ptr_cr_ret) {
15121514
encCrStrBufCat(runtime, str, ptr.getUnsafeBytes(), ptr.getBegin(), ptr.getRealSize(), ptrEnc, ptr_cr, ptr_cr_ret);
15131515
}
1514-
public static void encCrStrBufCat(Ruby runtime, RubyString str, byte[] ptrBytes, int ptr, int len, Encoding ptrEnc, int ptr_cr, int[] ptr_cr_ret) {
1515-
Encoding strEnc = str.getEncoding();
1516+
public static void encCrStrBufCat(Ruby runtime, CodeRangeable str, byte[] ptrBytes, int ptr, int len, Encoding ptrEnc, int ptr_cr, int[] ptr_cr_ret) {
1517+
Encoding strEnc = str.getByteList().getEncoding();
15161518
Encoding resEnc;
15171519
int str_cr, res_cr;
15181520
boolean incompatible = false;
15191521

1520-
str_cr = str.size() > 0 ? str.getCodeRange() : StringSupport.CR_7BIT;
1522+
str_cr = str.getByteList().getRealSize() > 0 ? str.getCodeRange() : StringSupport.CR_7BIT;
15211523

15221524
if (strEnc == ptrEnc) {
15231525
if (str_cr == StringSupport.CR_UNKNOWN) {
@@ -1530,9 +1532,10 @@ public static void encCrStrBufCat(Ruby runtime, RubyString str, byte[] ptrBytes,
15301532
if (len == 0) {
15311533
return;
15321534
}
1533-
if (str.size() == 0) {
1535+
if (str.getByteList().getRealSize() == 0) {
15341536
rbStrBufCat(runtime, str, ptrBytes, ptr, len);
1535-
str.setEncodingAndCodeRange(ptrEnc, ptr_cr);
1537+
str.getByteList().setEncoding(ptrEnc);
1538+
str.setCodeRange(ptr_cr);
15361539
return;
15371540
}
15381541
incompatible = true;
@@ -1586,7 +1589,8 @@ public static void encCrStrBufCat(Ruby runtime, RubyString str, byte[] ptrBytes,
15861589
// MRI checks for len < 0 here, but I don't think that's possible for us
15871590

15881591
strBufCat(runtime, str, ptrBytes, ptr, len);
1589-
str.setEncodingAndCodeRange(resEnc, res_cr);
1592+
str.getByteList().setEncoding(resEnc);
1593+
str.setCodeRange(res_cr);
15901594
}
15911595

15921596
// econv_args

core/src/test/java/org/jruby/test/TestRequire.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public TestRequire(String name) {
4444
public void testRubyRequire() throws Exception {
4545
String result = eval("require 'A/C'; puts A::C.new.meth");
4646
assertEquals("ok", result);
47-
result = eval("$: << 'A'; require 'B'; puts B.new.meth");
47+
// the current working directory is core/
48+
result = eval("$: << 'src/test/ruby/A'; require 'B'; puts B.new.meth");
4849
assertEquals("ok", result);
4950
}
5051

File renamed without changes.

core/src/test/resources/rubygems/defaults/jruby.rb

Lines changed: 0 additions & 9 deletions
This file was deleted.

lib/ruby/stdlib/rubygems/defaults/jruby.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,7 @@ def spec_directories_from_classpath
109109
# some classloader return directory info. use only the "protocols"
110110
# which jruby understands
111111
stuff.select! { |s| File.directory?( s ) }
112-
if File.directory?( 'uri:classloader://specifications' )
113-
[ 'uri:classloader://specifications' ] + stuff
114-
else
115-
stuff
116-
end
112+
[ 'uri:classloader://specifications' ] + stuff
117113
end
118114
end
119115
end

lib/ruby/truffle/shims/time.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This
2+
# code is released under a tri EPL/GPL/LGPL license. You can use it,
3+
# redistribute it and/or modify it under the terms of the:
4+
#
5+
# Eclipse Public License version 1.0
6+
# GNU General Public License version 2
7+
# GNU Lesser General Public License version 2.1
8+
9+
# Empty time file - everything is loaded by default at the moment

maven/jruby-complete/src/templates/osgi_many_bundles_with_embedded_gems/test/src/test/java/org/jruby/embed/osgi/test/JRubyOsgiEmbedTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void testJRubyCreate() throws Exception {
9393

9494
String gemPath = (String) jruby.runScriptlet( "Gem::Specification.dirs.inspect" );
9595
gemPath = gemPath.replaceAll( "bundle[^:]*://[^/]*", "bundle:/" );
96-
assertEquals( gemPath, "[\"uri:bundle://specifications\", \"uri:classloader:/META-INF/jruby.home/lib/ruby/gems/shared/specifications\"]" );
96+
assertEquals( gemPath, "[\"uri:bundle://specifications\", \"uri:classloader:/META-INF/jruby.home/lib/ruby/gems/shared/specifications\", \"uri:classloader:/specifications\"]" );
9797

9898
// ensure we can load rake from the default gems
9999
boolean loaded = (Boolean) jruby.runScriptlet( "require 'rake'" );

maven/jruby/src/it/extended/src/test/java/org/example/SimpleTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import java.util.Arrays;
66
import java.io.File;
77
import java.io.StringWriter;
8+
import java.net.URL;
9+
import java.net.URLClassLoader;
810

911
import org.jruby.embed.LocalContextScope;
1012
import org.jruby.embed.ScriptingContainer;
@@ -69,7 +71,7 @@ private void runIt(String index) throws Exception {
6971
private void runIt(String index, String script) throws Exception {
7072
ClassLoader cl = Thread.currentThread().getContextClassLoader();
7173
try {
72-
//Thread.currentThread().setContextClassLoader();
74+
Thread.currentThread().setContextClassLoader(new URLClassLoader( new URL[] {}, null ));
7375
System.err.println("\n\nrunning --------- " + index + "\n");
7476
ScriptingContainer container = newScriptingContainer();
7577
if (script != null) container.runScriptlet( script );
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
unstable:ThreadGroup#list returns the list of threads in the group

0 commit comments

Comments
 (0)