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/KernelNodes.java
	truffle/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java
	truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
  • Loading branch information
chrisseaton committed Feb 18, 2015
2 parents 76cab7b + 2238abf commit 9bc3439
Show file tree
Hide file tree
Showing 84 changed files with 1,321 additions and 687 deletions.
6 changes: 2 additions & 4 deletions core/src/main/java/org/jruby/RubyClassPathVariable.java
Expand Up @@ -65,14 +65,12 @@ public IRubyObject append(ThreadContext context, IRubyObject obj) {
} else {
paths = context.runtime.newArray(obj).toJavaArray();
}

boolean is1_8 = context.getRuntime().is1_8();

for (IRubyObject path: paths) {
try {
URL url = getURL(path.convertToString().toString());
if (url.getProtocol().equals("file")) {
path = is1_8 ? RubyFile.expand_path(context, null, new IRubyObject[]{ path })
: RubyFile.expand_path19(context, null, new IRubyObject[]{ path });
path = RubyFile.expand_path19(context, null, new IRubyObject[]{ path });
url = getURL(path.convertToString().toString());
}
getRuntime().getJRubyClassLoader().addURL(url);
Expand Down
11 changes: 3 additions & 8 deletions core/src/main/java/org/jruby/RubyEncoding.java
Expand Up @@ -175,20 +175,15 @@ public static Encoding areCompatible(CodeRangeable obj1, CodeRangeable obj2) {

if (obj2.getByteList().getRealSize() == 0) return enc1;
if (obj1.getByteList().getRealSize() == 0) {
return enc1.isAsciiCompatible() && obj2 instanceof RubyString &&
((RubyString) obj2).isAsciiOnly() ? enc1 : enc2;
return enc1.isAsciiCompatible() && StringSupport.isAsciiOnly(obj2) ? enc1 : enc2;
}

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

int cr1 = obj1.scanForCodeRange();
if (obj2 instanceof RubyString) {
int cr2 = obj2.scanForCodeRange();
return areCompatible(enc1, cr1, enc2, cr2);
}
if (cr1 == StringSupport.CR_7BIT) return enc2;
int cr2 = obj2.scanForCodeRange();

return null;
return areCompatible(enc1, cr1, enc2, cr2);
}

public static Encoding areCompatible(Encoding enc1, Encoding enc2) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyString.java
Expand Up @@ -217,7 +217,7 @@ public final boolean isCodeRangeAsciiOnly() {

// rb_enc_str_asciionly_p
public final boolean isAsciiOnly() {
return value.getEncoding().isAsciiCompatible() && scanForCodeRange() == CR_7BIT;
return StringSupport.isAsciiOnly(this);
}

@Override
Expand Down
Expand Up @@ -230,9 +230,7 @@ protected void doDebug() {
ensureInstrsReady();
LOG.info("Executing '" + method.getName() + "'");
if (!displayedCFG) {
CFG cfg = method.getCFG();
LOG.info("Graph:\n" + cfg.toStringGraph());
LOG.info("CFG:\n" + cfg.toStringInstrs());
LOG.info(method.debugOutput());
displayedCFG = true;
}
}
Expand Down
18 changes: 15 additions & 3 deletions core/src/main/java/org/jruby/ir/IRScope.java
Expand Up @@ -441,6 +441,10 @@ public boolean canReceiveNonlocalReturns() {
}

public CFG buildCFG() {
if (getCFG() != null) {
return getCFG();
}

CFG newCFG = new CFG(this);
newCFG.build(getInstrs());
// Clear out instruction list after CFG has been built.
Expand Down Expand Up @@ -641,9 +645,7 @@ private void setupLinearization() {
depends(linearization());
} catch (RuntimeException e) {
LOG.error("Error linearizing cfg: ", e);
CFG c = cfg();
LOG.error("\nGraph:\n" + c.toStringGraph());
LOG.error("\nInstructions:\n" + c.toStringInstrs());
LOG.error(this.debugOutput());
throw e;
}
}
Expand Down Expand Up @@ -764,6 +766,16 @@ public String toString() {
return getScopeType() + " " + getName() + "[" + getFileName() + ":" + getLineNumber() + "]";
}

public String debugOutput() {
if (this.cfg == null) {
return "Instructions:\n" + this.toStringInstrs();
} else {
return
"\nCFG:\n" + this.cfg.toStringGraph() +
"\nInstructions:\n" + this.cfg.toStringInstrs();
}
}

public String toStringInstrs() {
StringBuilder b = new StringBuilder();

Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/org/jruby/ir/interpreter/Interpreter.java
Expand Up @@ -235,8 +235,7 @@ private static BeginEndInterpreterContext prepareIC(ThreadContext context, Dynam
BeginEndInterpreterContext ic = (BeginEndInterpreterContext) script.prepareForInterpretation();

if (IRRuntimeHelpers.isDebug()) {
LOG.info("Graph:\n" + script.cfg().toStringGraph());
LOG.info("CFG:\n" + script.cfg().toStringInstrs());
LOG.info(script.debugOutput());
}

return ic;
Expand Down
Expand Up @@ -161,7 +161,16 @@ public String toString() {
buf.append(fileName).append(':').append(lineNumber);
if (name != null) buf.append(' ').append(name);

buf.append("\nCFG:\n").append(cfg.toStringInstrs());
if (cfg != null) {
buf.append("\nCFG:\n").append(cfg.toStringInstrs());
} else {
int i = 0;
for (Instr instr : instructions) {
if (i > 0) buf.append("\n");
buf.append(" ").append(i).append('\t').append(instr);
i++;
}
}

return buf.toString();
}
Expand Down
Expand Up @@ -29,9 +29,7 @@ public InterpretedIRBlockBody(IRClosure closure, Signature signature) {
public InterpreterContext ensureInstrsReady() {
if (IRRuntimeHelpers.isDebug() && !displayedCFG) {
LOG.info("Executing '" + closure + "' (pushScope=" + pushScope + ", reuseParentScope=" + reuseParentScope);
CFG cfg = closure.getCFG();
LOG.info("Graph:\n" + cfg.toStringGraph());
LOG.info("CFG:\n" + cfg.toStringInstrs());
LOG.info(closure.debugOutput());
displayedCFG = true;
}
// Always prepared in the context of parent scope -- so a null value here is a bug.
Expand Down
Expand Up @@ -147,9 +147,9 @@ private FoundLibrary findResourceLibrary(String baseName, String suffix) {

// FIXME: to_path should not be called n times it should only be once and that means a cache which would
// also reduce all this casting and/or string creates.
// (mkristian) would it make sense to turn $LOAD_PATH into something like RubyClassPathVariable where we could cache
// the Strings ?
private String getPath(IRubyObject loadPathEntry) {
if (runtime.is1_8()) return loadPathEntry.convertToString().asJavaString();

return RubyFile.get_path(runtime.getCurrentContext(), loadPathEntry).asJavaString();
}

Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/util/ByteListHolder.java
Expand Up @@ -30,6 +30,7 @@

public interface ByteListHolder {
public ByteList getByteList();
public void modify();
public void modify(int length);
public Encoding checkEncoding(ByteListHolder other);
}
22 changes: 11 additions & 11 deletions core/src/main/java/org/jruby/util/IdUtil.java
Expand Up @@ -33,22 +33,22 @@ public final class IdUtil {
/**
* rb_is_const_id and is_const_id
*/
public static boolean isConstant(String id) {
return Character.isUpperCase(id.charAt(0));
public static boolean isConstant(String id) {
return Character.isUpperCase(id.charAt(0));
}

/**
* rb_is_class_id and is_class_id
*/
public static boolean isClassVariable(String id) {
return id.length()>1 && id.charAt(0) == '@' && id.charAt(1) == '@';
public static boolean isClassVariable(String id) {
return id.length() > 1 && id.charAt(0) == '@' && id.charAt(1) == '@';
}

/**
* rb_is_instance_id and is_instance_id
*/
public static boolean isInstanceVariable(String id) {
return id.length()>0 && id.charAt(0) == '@' && (id.length() < 2 || id.charAt(1) != '@');
public static boolean isInstanceVariable(String id) {
return id.length() > 0 && id.charAt(0) == '@' && (id.length() < 2 || id.charAt(1) != '@');
}

/**
Expand All @@ -65,8 +65,8 @@ public static boolean isPredicate(String id) {
/**
* rb_is_local_id and is_local_id
*/
public static boolean isLocal(String id) {
return !isGlobal(id) && !isClassVariable(id) && !isInstanceVariable(id) && !isConstant(id) && !isPredicate(id) && !isSpecial(id);
public static boolean isLocal(String id) {
return !isGlobal(id) && !isClassVariable(id) && !isInstanceVariable(id) && !isConstant(id) && !isPredicate(id) && !isSpecial(id);
}

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

public static boolean isAttrSet(String id) {
return id.endsWith("=");
}
public static boolean isAttrSet(String id) {
return id.endsWith("=");
}

public static boolean isValidConstantName(String id) {
char c;
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/util/StringSupport.java
Expand Up @@ -1275,4 +1275,8 @@ public static void replaceInternal19(int beg, int len, CodeRangeable source, Cod
cr = CodeRangeSupport.codeRangeAnd(cr, repl.getCodeRange());
if (cr != CR_BROKEN) source.setCodeRange(cr);
}

public static boolean isAsciiOnly(CodeRangeable string) {
return string.getByteList().getEncoding().isAsciiCompatible() && string.scanForCodeRange() == CR_7BIT;
}
}
22 changes: 13 additions & 9 deletions core/src/main/java/org/jruby/util/io/EncodingUtils.java
Expand Up @@ -38,7 +38,9 @@
import org.jruby.runtime.encoding.EncodingCapable;
import org.jruby.runtime.encoding.EncodingService;
import org.jruby.util.ByteList;
import org.jruby.util.ByteListHolder;
import org.jruby.util.CodeRangeSupport;
import org.jruby.util.CodeRangeable;
import org.jruby.util.StringSupport;
import org.jruby.util.TypeConverter;

Expand Down Expand Up @@ -1461,7 +1463,7 @@ public static void rbStrBufCat(Ruby runtime, RubyString str, ByteList ptr) {
// negative length check here, we shouldn't need
strBufCat(runtime, str, ptr);
}
public static void rbStrBufCat(Ruby runtime, RubyString str, byte[] ptrBytes, int ptr, int len) {
public static void rbStrBufCat(Ruby runtime, ByteListHolder str, byte[] ptrBytes, int ptr, int len) {
if (len == 0) return;
// negative length check here, we shouldn't need
strBufCat(runtime, str, ptrBytes, ptr, len);
Expand All @@ -1476,7 +1478,7 @@ public static void rbStrBufCat(Ruby runtime, ByteList str, byte[] ptrBytes, int
public static void strBufCat(Ruby runtime, RubyString str, ByteList ptr) {
strBufCat(runtime, str, ptr.getUnsafeBytes(), ptr.getBegin(), ptr.getRealSize());
}
public static void strBufCat(Ruby runtime, RubyString str, byte[] ptrBytes, int ptr, int len) {
public static void strBufCat(Ruby runtime, ByteListHolder str, byte[] ptrBytes, int ptr, int len) {
str.modify();
strBufCat(str.getByteList(), ptrBytes, ptr, len);
}
Expand Down Expand Up @@ -1508,16 +1510,16 @@ public static void encStrBufCat(Ruby runtime, RubyString str, byte[] ptrBytes, i
}

// rb_enc_cr_str_buf_cat
public static void encCrStrBufCat(Ruby runtime, RubyString str, ByteList ptr, Encoding ptrEnc, int ptr_cr, int[] ptr_cr_ret) {
public static void encCrStrBufCat(Ruby runtime, CodeRangeable str, ByteList ptr, Encoding ptrEnc, int ptr_cr, int[] ptr_cr_ret) {
encCrStrBufCat(runtime, str, ptr.getUnsafeBytes(), ptr.getBegin(), ptr.getRealSize(), ptrEnc, ptr_cr, ptr_cr_ret);
}
public static void encCrStrBufCat(Ruby runtime, RubyString str, byte[] ptrBytes, int ptr, int len, Encoding ptrEnc, int ptr_cr, int[] ptr_cr_ret) {
Encoding strEnc = str.getEncoding();
public static void encCrStrBufCat(Ruby runtime, CodeRangeable str, byte[] ptrBytes, int ptr, int len, Encoding ptrEnc, int ptr_cr, int[] ptr_cr_ret) {
Encoding strEnc = str.getByteList().getEncoding();
Encoding resEnc;
int str_cr, res_cr;
boolean incompatible = false;

str_cr = str.size() > 0 ? str.getCodeRange() : StringSupport.CR_7BIT;
str_cr = str.getByteList().getRealSize() > 0 ? str.getCodeRange() : StringSupport.CR_7BIT;

if (strEnc == ptrEnc) {
if (str_cr == StringSupport.CR_UNKNOWN) {
Expand All @@ -1530,9 +1532,10 @@ public static void encCrStrBufCat(Ruby runtime, RubyString str, byte[] ptrBytes,
if (len == 0) {
return;
}
if (str.size() == 0) {
if (str.getByteList().getRealSize() == 0) {
rbStrBufCat(runtime, str, ptrBytes, ptr, len);
str.setEncodingAndCodeRange(ptrEnc, ptr_cr);
str.getByteList().setEncoding(ptrEnc);
str.setCodeRange(ptr_cr);
return;
}
incompatible = true;
Expand Down Expand Up @@ -1586,7 +1589,8 @@ public static void encCrStrBufCat(Ruby runtime, RubyString str, byte[] ptrBytes,
// MRI checks for len < 0 here, but I don't think that's possible for us

strBufCat(runtime, str, ptrBytes, ptr, len);
str.setEncodingAndCodeRange(resEnc, res_cr);
str.getByteList().setEncoding(resEnc);
str.setCodeRange(res_cr);
}

// econv_args
Expand Down
3 changes: 2 additions & 1 deletion core/src/test/java/org/jruby/test/TestRequire.java
Expand Up @@ -44,7 +44,8 @@ public TestRequire(String name) {
public void testRubyRequire() throws Exception {
String result = eval("require 'A/C'; puts A::C.new.meth");
assertEquals("ok", result);
result = eval("$: << 'A'; require 'B'; puts B.new.meth");
// the current working directory is core/
result = eval("$: << 'src/test/ruby/A'; require 'B'; puts B.new.meth");
assertEquals("ok", result);
}

Expand Down
File renamed without changes.
9 changes: 0 additions & 9 deletions core/src/test/resources/rubygems/defaults/jruby.rb

This file was deleted.

6 changes: 1 addition & 5 deletions lib/ruby/stdlib/rubygems/defaults/jruby.rb
Expand Up @@ -109,11 +109,7 @@ def spec_directories_from_classpath
# some classloader return directory info. use only the "protocols"
# which jruby understands
stuff.select! { |s| File.directory?( s ) }
if File.directory?( 'uri:classloader://specifications' )
[ 'uri:classloader://specifications' ] + stuff
else
stuff
end
[ 'uri:classloader://specifications' ] + stuff
end
end
end
Expand Down
9 changes: 9 additions & 0 deletions lib/ruby/truffle/shims/time.rb
@@ -0,0 +1,9 @@
# Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
# Eclipse Public License version 1.0
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

# Empty time file - everything is loaded by default at the moment
Expand Up @@ -93,7 +93,7 @@ public void testJRubyCreate() throws Exception {

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

// ensure we can load rake from the default gems
boolean loaded = (Boolean) jruby.runScriptlet( "require 'rake'" );
Expand Down
Expand Up @@ -5,6 +5,8 @@
import java.util.Arrays;
import java.io.File;
import java.io.StringWriter;
import java.net.URL;
import java.net.URLClassLoader;

import org.jruby.embed.LocalContextScope;
import org.jruby.embed.ScriptingContainer;
Expand Down Expand Up @@ -69,7 +71,7 @@ private void runIt(String index) throws Exception {
private void runIt(String index, String script) throws Exception {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
try {
//Thread.currentThread().setContextClassLoader();
Thread.currentThread().setContextClassLoader(new URLClassLoader( new URL[] {}, null ));
System.err.println("\n\nrunning --------- " + index + "\n");
ScriptingContainer container = newScriptingContainer();
if (script != null) container.runScriptlet( script );
Expand Down
1 change: 1 addition & 0 deletions spec/tags/ruby/core/threadgroup/list_tags.txt
@@ -0,0 +1 @@
unstable:ThreadGroup#list returns the list of threads in the group

0 comments on commit 9bc3439

Please sign in to comment.