Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Sep 16, 2014
2 parents 888021e + b55585c commit eecbbdc
Show file tree
Hide file tree
Showing 80 changed files with 1,409 additions and 1,417 deletions.
15 changes: 11 additions & 4 deletions core/src/main/java/org/jruby/Main.java
Expand Up @@ -203,12 +203,19 @@ public static void main(String[] args) {
} catch (RaiseException rj) {
System.exit(handleRaiseException(rj));
} catch (Throwable t) {
// print out as a nice Ruby backtrace
System.err.println(ThreadContext.createRawBacktraceStringFromThrowable(t));
while ((t = t.getCause()) != null) {
System.err.println("Caused by:");
// If a Truffle exception gets this far it's a hard failure - don't try and dress it up as a Ruby exception

if (main.config.getCompileMode() == RubyInstanceConfig.CompileMode.TRUFFLE) {
t.printStackTrace(System.err);
} else {
// print out as a nice Ruby backtrace
System.err.println(ThreadContext.createRawBacktraceStringFromThrowable(t));
while ((t = t.getCause()) != null) {
System.err.println("Caused by:");
System.err.println(ThreadContext.createRawBacktraceStringFromThrowable(t));
}
}

System.exit(1);
}
}
Expand Down
29 changes: 21 additions & 8 deletions core/src/main/java/org/jruby/Ruby.java
Expand Up @@ -155,7 +155,6 @@
import java.net.BindException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.channels.Channel;
import java.nio.channels.ClosedChannelException;
import java.security.AccessControlException;
import java.security.SecureRandom;
Expand Down Expand Up @@ -636,9 +635,15 @@ public IRubyObject runWithGetsLoop(Node scriptNode, boolean printing, boolean pr
if (compile) {
try {
script = tryCompile(scriptNode);
} catch (Exception e) {
if (Options.JIT_LOGGING_VERBOSE.load()) {
e.printStackTrace();
if (Options.JIT_LOGGING.load()) {
LOG.info("Successfully compiled: " + scriptNode.getPosition().getFile());
}
} catch (Throwable e) {
if (Options.JIT_LOGGING.load()) {
LOG.error("Failed to compile: " + scriptNode.getPosition().getFile());
if (Options.JIT_LOGGING_VERBOSE.load()) {
LOG.error(e);
}
}
}
if (compile && script == null) {
Expand Down Expand Up @@ -1272,7 +1277,7 @@ && getInstanceConfig().getCompileMode() != CompileMode.TRUFFLE) {
}

// out of base boot mode
booting = false;
bootingCore = false;

// init Ruby-based kernel
if (getInstanceConfig().getCompileMode() != CompileMode.TRUFFLE) {
Expand All @@ -1299,6 +1304,9 @@ && getInstanceConfig().getCompileMode() != CompileMode.TRUFFLE) {
}

setNetworkStack();

// Done booting JRuby runtime
bootingRuntime = false;

// Require in all libraries specified on command line
for (String scriptName : config.getRequiredLibraries()) {
Expand Down Expand Up @@ -1730,7 +1738,7 @@ private void initBuiltins() {
addLazyBuiltin("tempfile.jar", "tempfile", "org.jruby.ext.tempfile.TempfileLibrary");
addLazyBuiltin("fcntl.rb", "fcntl", "org.jruby.ext.fcntl.FcntlLibrary");
addLazyBuiltin("yecht.jar", "yecht", "YechtService");
addLazyBuiltin("pathname_ext.jar", "pathname_ext", "org.jruby.ext.pathname.PathnameLibrary");
addLazyBuiltin("pathname.jar", "pathname", "org.jruby.ext.pathname.PathnameLibrary");
addLazyBuiltin("truffelize.jar", "truffelize", "org.jruby.ext.truffelize.TruffelizeLibrary");

addLazyBuiltin("mathn/complex.jar", "mathn/complex", "org.jruby.ext.mathn.Complex");
Expand Down Expand Up @@ -4559,8 +4567,12 @@ public boolean isFloatReopened() {
return floatReopened;
}

public boolean isBootingCore() {
return bootingCore;
}

public boolean isBooting() {
return booting;
return bootingRuntime;
}

public CoverageData getCoverageData() {
Expand Down Expand Up @@ -4924,7 +4936,8 @@ public FilenoUtil getFilenoUtil() {
floatInvalidator = OptoFactory.newGlobalInvalidator(0);
private boolean fixnumReopened, floatReopened;

private volatile boolean booting = true;
private volatile boolean bootingCore = true;
private volatile boolean bootingRuntime = true;

private RubyHash envObject;

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyArray.java
Expand Up @@ -3379,7 +3379,7 @@ public IRubyObject product19(ThreadContext context, IRubyObject[] args, Block bl
int counters[] = new int[n];

arrays[0] = this;
for (int i = 1; i < n; i++) arrays[i] = args[i - 1].convertToArray();
for (int i = 1; i < n; i++) arrays[i] = TypeConverter.to_ary(context, args[i - 1]);

int resultLen = 1;
for (int i = 0; i < n; i++) {
Expand Down
89 changes: 68 additions & 21 deletions core/src/main/java/org/jruby/RubyClass.java
Expand Up @@ -30,6 +30,7 @@
***** END LICENSE BLOCK *****/
package org.jruby;

import org.jruby.runtime.Arity;
import org.jruby.runtime.ivars.VariableAccessor;
import static org.jruby.util.CodegenUtils.ci;
import static org.jruby.util.CodegenUtils.p;
Expand Down Expand Up @@ -59,7 +60,6 @@
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.compiler.impl.SkinnyMethodAdapter;
import org.jruby.exceptions.RaiseException;
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.java.codegen.RealClassGenerator;
import org.jruby.java.codegen.Reified;
Expand Down Expand Up @@ -616,30 +616,77 @@ public IRubyObject finvoke(ThreadContext context, IRubyObject self, String name)
}

public IRubyObject finvokeChecked(ThreadContext context, IRubyObject self, String name) {
DynamicMethod method = searchMethod(name);
if(method.isUndefined()) {
DynamicMethod methodMissing = searchMethod("method_missing");
if(methodMissing.isUndefined() || methodMissing.equals(context.runtime.getDefaultMethodMissing())) {
return null;
RubyClass klass = self.getMetaClass();
DynamicMethod me;
if (!checkFuncallRespondTo(context, self.getMetaClass(), self, name))
return null;

me = searchMethod(name);
if (!checkFuncallCallable(context, me, CallType.FUNCTIONAL, self)) {
return checkFuncallMissing(context, klass, self, name);
}
return me.call(context, self, klass, name);
}

// MRI: check_funcall_exec
private static IRubyObject checkFuncallExec(ThreadContext context, IRubyObject self, String name, IRubyObject... args) {
IRubyObject[] newArgs = new IRubyObject[args.length + 1];
System.arraycopy(args, 0, newArgs, 1, args.length);
newArgs[0] = context.runtime.newSymbol(name);
return self.callMethod(context, "method_missing", newArgs);
}

// MRI: check_funcall_failed
private static IRubyObject checkFuncallFailed(ThreadContext context, IRubyObject self, String name, RubyClass expClass, IRubyObject... args) {
if (self.respondsTo(name)) {
throw context.runtime.newRaiseException(expClass, name);
}
return null;
}

// MRI: check_funcall_respond_to
private static boolean checkFuncallRespondTo(ThreadContext context, RubyClass klass, IRubyObject recv, String mid) {
Ruby runtime = context.runtime;
RubyClass defined_class;
DynamicMethod me = klass.searchMethod("respond_to?");

if (me != null && !me.isUndefined()) {
Arity arity = me.getArity();

if (arity.getValue() > 2)
throw runtime.newArgumentError("respond_to? must accept 1 or 2 arguments (requires " + arity + ")");

IRubyObject result = me.call(context, recv, klass, "respond_to?", runtime.newString(mid), runtime.getTrue());
if (!result.isTrue()) {
return false;
}
}
return true;
}

// MRI: check_funcall_callable
public static boolean checkFuncallCallable(ThreadContext context, DynamicMethod method, CallType callType, IRubyObject self) {
return rbMethodCallStatus(context, method, callType, self);
}

// MRI: rb_method_call_status
// FIXME: Partial impl because we don't have these "NOEX" flags
public static boolean rbMethodCallStatus(ThreadContext context, DynamicMethod method, CallType callType, IRubyObject self) {
return !method.isUndefined() && method.isCallableFrom(self, callType);
}

private static IRubyObject checkFuncallMissing(ThreadContext context, RubyClass klass, IRubyObject self, String method, IRubyObject... args) {
Ruby runtime = context.runtime;
if (klass.isMethodBuiltin("method_missing")) {
return null;
}
else {
try {
return Helpers.callMethodMissing(context, self, method.getVisibility(), name, CallType.FUNCTIONAL, Block.NULL_BLOCK);
} catch(RaiseException e) {
if(context.runtime.getNoMethodError().isInstance(e.getException())) {
if(self.respondsTo(name)) {
throw e;
} else {
// we swallow, so we also must clear $!
context.setErrorInfo(context.nil);
return null;
}
} else {
throw e;
}
return checkFuncallExec(context, self, method, args);
} catch (Exception e) {
return checkFuncallFailed(context, self, method, runtime.getNoMethodError(), args);
}
}
return method.call(context, self, this, name);
}

public IRubyObject invoke(ThreadContext context, IRubyObject self, String name,
Expand Down Expand Up @@ -990,7 +1037,7 @@ public void addInvalidatorsAndFlush(List<Invalidator> invalidators) {
invalidators.add(methodInvalidator);

// if we're not at boot time, don't bother fully clearing caches
if (!runtime.isBooting()) cachedMethods.clear();
if (!runtime.isBootingCore()) cachedMethods.clear();

// no subclasses, don't bother with lock and iteration
if (subclasses == null || subclasses.isEmpty()) return;
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/java/org/jruby/RubyComplex.java
Expand Up @@ -910,6 +910,14 @@ public IRubyObject marshal_load(ThreadContext context, IRubyObject arg) {
return this;
}

/** nucomp_to_c
*
*/
@JRubyMethod(name = "to_c")
public IRubyObject to_c(ThreadContext context) {
return this;
}

/** nucomp_to_i
*
*/
Expand Down
25 changes: 17 additions & 8 deletions core/src/main/java/org/jruby/RubyFile.java
Expand Up @@ -1212,9 +1212,7 @@ public IRubyObject fileOpenGeneric(ThreadContext context, IRubyObject filename,

// mri: FilePathValue/rb_get_path/rb_get_patch_check
public static RubyString get_path(ThreadContext context, IRubyObject path) {
if (path instanceof RubyString) {
return (RubyString)path;
}
if (path instanceof RubyString) return (RubyString) path;

if (path.respondsTo("to_path")) path = path.callMethod(context, "to_path");

Expand Down Expand Up @@ -1242,7 +1240,20 @@ private static RubyString filePathConvert(ThreadContext context, RubyString path

return path;
}



public static FileResource fileResource(ThreadContext context, IRubyObject pathOrFile) {
Ruby runtime = context.runtime;

if (pathOrFile instanceof RubyFile) {
return JRubyFile.createResource(runtime, ((RubyFile) pathOrFile).getPath());
} else if (pathOrFile instanceof RubyIO) {
return JRubyFile.createResource(runtime, ((RubyIO) pathOrFile).openFile.getPath());

}

return JRubyFile.createResource(runtime, get_path(context, pathOrFile).toString());
}
/**
* Get the fully-qualified JRubyFile object for the path, taking into
* account the runtime's current directory.
Expand All @@ -1254,11 +1265,9 @@ public static FileResource fileResource(IRubyObject pathOrFile) {
return JRubyFile.createResource(runtime, ((RubyFile) pathOrFile).getPath());
} else if (pathOrFile instanceof RubyIO) {
return JRubyFile.createResource(runtime, ((RubyIO) pathOrFile).openFile.getPath());
} else {
RubyString pathStr = get_path(runtime.getCurrentContext(), pathOrFile);

return JRubyFile.createResource(runtime, pathStr.toString());
}

return JRubyFile.createResource(runtime, get_path(runtime.getCurrentContext(), pathOrFile).toString());
}

@Deprecated // Use fileResource instead
Expand Down
7 changes: 2 additions & 5 deletions core/src/main/java/org/jruby/RubyFileStat.java
Expand Up @@ -126,12 +126,9 @@ private void setup(String filename, boolean lstat) {
}

file = JRubyFile.createResource(getRuntime().getPosix(), getRuntime().getCurrentDirectory(), filename);

if (!file.exists()) {
throw getRuntime().newErrnoENOENTError("No such file or directory - " + filename);
}

stat = lstat ? file.lstat() : file.stat();

if (stat == null) throw getRuntime().newErrnoFromInt(getRuntime().getPosix().errno());
}

public IRubyObject initialize(IRubyObject fname, Block unusedBlock) {
Expand Down

0 comments on commit eecbbdc

Please sign in to comment.