Skip to content

Commit

Permalink
Merge branch 'master' into expr_tree
Browse files Browse the repository at this point in the history
  • Loading branch information
subbuss committed Mar 8, 2012
2 parents d69321c + 0d552ae commit 744edda
Show file tree
Hide file tree
Showing 43 changed files with 2,095 additions and 1,124 deletions.
18 changes: 11 additions & 7 deletions build.xml
Expand Up @@ -708,16 +708,20 @@
</target>

<target name="compile-stdlib" unless="test">
<copy todir="${build.dir}/stdlib">
<fileset dir="lib/ruby/1.8">
<include name="**/*.rb"/>
</fileset>
</copy>
<java classname="org.jruby.Main" fork="true" maxmemory="${jruby.launch.memory}" failonerror="true" dir="${build.dir}/stdlib">
<mkdir dir="${build.dir}/stdlib"/>
<echo message="Compiling 1.8 stdlib..."/>
<java classname="org.jruby.Main" fork="true" maxmemory="${jruby.launch.memory}" failonerror="true">
<classpath refid="jruby.execute.classpath"/>
<sysproperty key="jruby.home" value="${basedir}"/>
<jvmarg line="-ea ${java.opts}"/>
<arg line="--1.8 -I bin/ -S jrubyc --target ${build.dir}/stdlib lib/ruby/1.8"/>
</java>
<echo message="Compiling 1.9 stdlib..."/>
<java classname="org.jruby.Main" fork="true" maxmemory="${jruby.launch.memory}" failonerror="true">
<classpath refid="jruby.execute.classpath"/>
<sysproperty key="jruby.home" value="${basedir}"/>
<jvmarg line="-ea ${java.opts}"/>
<arg line="-I bin/ -S jrubyc ."/>
<arg line="--1.9 -I bin/ -S jrubyc --target ${build.dir}/stdlib lib/ruby/1.9"/>
</java>
</target>

Expand Down
5 changes: 3 additions & 2 deletions spec/java_integration/addons/throwable_spec.rb
Expand Up @@ -9,10 +9,11 @@
trace.should == ex.stack_trace.map(&:to_s)
end

it "implements backtrace=" do
it "implements backtrace= as a no-op" do
ex = java.lang.Exception.new
backtrace = ex.backtrace
ex.set_backtrace ['blah']
ex.backtrace.should == ['blah']
ex.backtrace.should == backtrace
end

it "implements to_s as message" do
Expand Down
8 changes: 3 additions & 5 deletions src/jruby/java/java_ext/java.lang.rb
Expand Up @@ -32,14 +32,12 @@ def <=>(a)

class java::lang::Throwable
def backtrace
@backtrace ||= stack_trace.map(&:to_s)
stack_trace.map(&:to_s)
end

def set_backtrace(trace)
unless trace.kind_of?(Array) && trace.all? {|x| x.kind_of?(String)}
raise TypeError.new("backtrace must be an Array of String")
end
@backtrace = trace
# ignored; Java exceptions can't be set to Ruby trace
trace
end

def message
Expand Down
4 changes: 4 additions & 0 deletions src/jruby/kernel19/io.rb
Expand Up @@ -8,4 +8,8 @@ class EAGAINReadable < Errno::EAGAIN
class EAGAINWritable < Errno::EAGAIN
include IO::WaitWritable
end

class EINPROGRESSWritable < Errno::EINPROGRESS
include IO::WaitWritable
end
end
16 changes: 16 additions & 0 deletions src/org/jruby/Ruby.java
Expand Up @@ -1392,6 +1392,12 @@ private void initCore() {
} else {
LoadService.reflectedLoad(this, "fiber", "org.jruby.ext.fiber.ThreadFiberLibrary", getJRubyClassLoader(), false);
}
} else {
if (RubyInstanceConfig.COROUTINE_FIBERS) {
addLazyBuiltin("jruby/fiber.jar", "jruby/fiber", "org.jruby.ext.fiber.CoroutineFiberLibrary");
} else {
addLazyBuiltin("jruby/fiber.jar", "jruby/fiber", "org.jruby.ext.fiber.ThreadFiberLibrary");
}
}

// Load the JRuby::Config module for accessing configuration settings from Ruby
Expand Down Expand Up @@ -1580,6 +1586,8 @@ public void load(Ruby runtime, boolean wrap) throws IOException {
};
addBuiltinIfAllowed("continuation.rb", dummy);
addBuiltinIfAllowed("io/nonblock.rb", dummy);
} else {
addLazyBuiltin("jruby/fiber_ext.rb", "jruby/fiber_ext", "org.jruby.ext.fiber.FiberExtLibrary");
}

if(RubyInstanceConfig.NATIVE_NET_PROTOCOL) {
Expand Down Expand Up @@ -3118,6 +3126,10 @@ public RaiseException newErrnoEINPROGRESSError() {
return newRaiseException(getErrno().getClass("EINPROGRESS"), "Operation now in progress");
}

public RaiseException newErrnoEINPROGRESSWritableError() {
return newLightweightErrnoException(getModule("JRuby").getClass("EINPROGRESSWritable"), "");
}

public RaiseException newErrnoENOPROTOOPTError() {
return newRaiseException(getErrno().getClass("ENOPROTOOPT"), "Protocol not available");
}
Expand Down Expand Up @@ -3199,6 +3211,10 @@ public RaiseException newErrnoEINPROGRESSError(String message) {
return newRaiseException(getErrno().getClass("EINPROGRESS"), message);
}

public RaiseException newErrnoEINPROGRESSWritableError(String message) {
return newLightweightErrnoException(getModule("JRuby").getClass("EINPROGRESSWritable"), message);
}

public RaiseException newErrnoEISCONNError(String message) {
return newRaiseException(getErrno().getClass("EISCONN"), message);
}
Expand Down
53 changes: 50 additions & 3 deletions src/org/jruby/RubyThread.java
Expand Up @@ -67,6 +67,8 @@
import org.jruby.runtime.ClassIndex;
import org.jruby.runtime.ObjectMarshal;
import static org.jruby.runtime.Visibility.*;

import org.jruby.util.cli.Options;
import org.jruby.util.io.BlockingIO;
import org.jruby.util.io.SelectorFactory;
import org.jruby.util.log.Logger;
Expand Down Expand Up @@ -138,6 +140,12 @@ public static enum Status { RUN, SLEEP, ABORTING, DEAD }
/** The list of locks this thread currently holds, so they can be released on exit */
private final List<Lock> heldLocks = new ArrayList<Lock>();

/** Whether or not this thread has been disposed of */
private volatile boolean disposed = false;

/** The thread's initial priority, for use in thread pooled mode */
private int initialPriority;

protected RubyThread(Ruby runtime, RubyClass type) {
super(runtime, type);

Expand Down Expand Up @@ -207,11 +215,46 @@ public ThreadContext getContext() {
public Thread getNativeThread() {
return threadImpl.nativeThread();
}

/**
* Dispose of the current thread by removing it from its parent ThreadGroup.
* Perform pre-execution tasks once the native thread is running, but we
* have not yet called the Ruby code for the thread.
*/
public void dispose() {
threadGroup.remove(this);
public void beforeStart() {
// store initial priority, for restoring pooled threads to normal
initialPriority = threadImpl.getPriority();

// set to "normal" priority
threadImpl.setPriority(Thread.NORM_PRIORITY);
}

/**
* Dispose of the current thread by tidying up connections to other stuff
*/
public synchronized void dispose() {
if (!disposed) {
disposed = true;

// remove from parent thread group
threadGroup.remove(this);

// unlock all locked locks
unlockAll();

// clear all thread locals
clearThreadLocals();

// reset thread priority to initial if pooling
if (Options.THREADPOOL_ENABLED.load()) {
threadImpl.setPriority(initialPriority);
}

// mark thread as DEAD
beDead();

// unregister from runtime's ThreadService
getRuntime().getThreadService().unregisterThread(this);
}
}

public static RubyClass createThreadClass(Ruby runtime) {
Expand Down Expand Up @@ -459,6 +502,10 @@ private synchronized Map<IRubyObject, IRubyObject> getThreadLocals() {
return threadLocalVariables;
}

private void clearThreadLocals() {
threadLocalVariables = null;
}

public final Map<Object, IRubyObject> getContextVariables() {
return contextVariables;
}
Expand Down
3 changes: 2 additions & 1 deletion src/org/jruby/common/IRubyWarnings.java
Expand Up @@ -90,7 +90,8 @@ public enum ID {
USELESS_EXPRESSION("USELESS_EXPRESSION"),
VOID_VALUE_EXPRESSION("VOID_VALUE_EXPRESSION"),
NAMED_CAPTURE_CONFLICT("NAMED_CAPTURE_CONFLICT"),
NON_PERSISTENT_JAVA_PROXY("NON_PERSISTENT_JAVA_PROXY");
NON_PERSISTENT_JAVA_PROXY("NON_PERSISTENT_JAVA_PROXY"),
LISTEN_SERVER_SOCKET("LISTEN_SERVER_SOCKET");

private final String id;

Expand Down
6 changes: 6 additions & 0 deletions src/org/jruby/compiler/ir/IRManager.java
@@ -1,5 +1,7 @@
package org.jruby.compiler.ir;

import java.util.List;
import org.jruby.compiler.ir.compiler_pass.CompilerPass;
import org.jruby.compiler.ir.operands.BooleanLiteral;
import org.jruby.compiler.ir.operands.Nil;

Expand Down Expand Up @@ -32,6 +34,10 @@ public IRModuleBody getObject() {
return object;
}

public List<CompilerPass> getCompilerPasses(IRScope scope) {
return null;
}

public IRModuleBody getClassMetaClass() {
return classMetaClass;
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/jruby/compiler/ir/IRScope.java
Expand Up @@ -828,7 +828,7 @@ private boolean computeScopeFlags(boolean receivesClosureArg, List<Instr> instrs
if (i instanceof CallBase) {
CallBase call = (CallBase) i;

Operand o = ((CallBase)i).getClosureArg(getManager().getNil());
Operand o = ((CallBase) i).getClosureArg(null);
if (o != null) {
if (o instanceof WrappedIRClosure) {
IRClosure cl = ((WrappedIRClosure)o).getClosure();
Expand Down
Expand Up @@ -5,13 +5,19 @@
import org.jruby.compiler.ir.dataflow.analyses.BindingLoadPlacementProblem;
import org.jruby.compiler.ir.dataflow.analyses.BindingStorePlacementProblem;

public class AddBindingInstructions implements CompilerPass {
public class AddBindingInstructions extends CompilerPass {
public static String[] NAMES = new String[] { "add_binding", "add_binding_instructions" };

public String getLabel() {
return "Add Binding Instructions";
}

public boolean isPreOrder() {
return false;
}

public void run(IRScope s) {
if (!(s instanceof IRMethod)) return;
public Object execute(IRScope s, Object... data) {
if (!(s instanceof IRMethod)) return null;

IRMethod m = (IRMethod) s;
// if (m.requiresBinding()) {
Expand All @@ -25,5 +31,7 @@ public void run(IRScope s) {
frp.compute_MOP_Solution();
frp.addLoads();
// }

return null;
}
}
16 changes: 13 additions & 3 deletions src/org/jruby/compiler/ir/compiler_pass/CFGBuilder.java
Expand Up @@ -2,12 +2,22 @@

import org.jruby.compiler.ir.IRScope;

public class CFGBuilder implements CompilerPass {
public class CFGBuilder extends CompilerPass {
public static String[] NAMES = new String[] { "cfg", "cfg_builder" };

public String getLabel() {
return "CFG Builder";
}
public boolean isPreOrder() {
return true;
}

public void run(IRScope scope) {
scope.buildCFG();
@Override
public Object previouslyRun(IRScope scope) {
return scope.getCFG();
}

public Object execute(IRScope scope, Object... data) {
return scope.buildCFG();
}
}
12 changes: 10 additions & 2 deletions src/org/jruby/compiler/ir/compiler_pass/CallSplitter.java
Expand Up @@ -2,12 +2,20 @@

import org.jruby.compiler.ir.IRScope;

public class CallSplitter implements CompilerPass {
public class CallSplitter extends CompilerPass {
public static String[] NAMES = new String[] {"split_calls"};

public String getLabel() {
return "Call Splitting";
}

public boolean isPreOrder() {
return true;
}

public void run(IRScope scope) {
public Object execute(IRScope scope, Object... data) {
scope.splitCalls();

return null;
}
}

0 comments on commit 744edda

Please sign in to comment.