Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: eed16e9cb907
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 25f27e5312e5
Choose a head ref
  • 3 commits
  • 4 files changed
  • 1 contributor

Commits on Oct 11, 2015

  1. Copy the full SHA
    62d7320 View commit details
  2. [Truffle] Add slow specs tags.

    eregon committed Oct 11, 2015
    Copy the full SHA
    4df9da4 View commit details
  3. [Truffle] Wait for full thread and fiber initialization.

    * So to make sure they are registered and such when {Fiber,Thread}.new returns.
    eregon committed Oct 11, 2015
    Copy the full SHA
    25f27e5 View commit details
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
fails:Thread::Backtrace::Location#path in a main script when the script is in the working directory when using a relative script path returns a path relative to the working directory
fails:Thread::Backtrace::Location#path in a main script when the script is in a sub directory of the working directory when using a relative script path returns a path relative to the working directory
fails:Thread::Backtrace::Location#path in a main script when the script is outside of the working directory when using a relative script path returns a path relative to the working directory
slow:Thread::Backtrace::Location#path in a main script when the script is in the working directory when using an absolute script path returns an absolute path
slow:Thread::Backtrace::Location#path in a main script when the script is in a sub directory of the working directory when using an absolute script path returns an absolute path
slow:Thread::Backtrace::Location#path in a main script when the script is outside of the working directory when using an absolute path returns an absolute path
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.truffle.runtime.subsystems.ThreadManager;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;

@CoreClass(name = "Fiber")
@@ -44,7 +45,16 @@ public static DynamicObject createRootFiber(RubyContext context, DynamicObject t

private static DynamicObject createFiber(DynamicObject thread, DynamicObject rubyClass, String name, boolean isRootFiber) {
assert RubyGuards.isRubyThread(thread);
return Layouts.FIBER.createFiber(Layouts.CLASS.getInstanceFactory(rubyClass), isRootFiber, new LinkedBlockingQueue<FiberMessage>(2), thread, name, null, true, null);
return Layouts.FIBER.createFiber(
Layouts.CLASS.getInstanceFactory(rubyClass),
isRootFiber,
new CountDownLatch(1),
new LinkedBlockingQueue<FiberMessage>(2),
thread,
name,
null,
true,
null);
}

public static void initialize(final RubyContext context, final DynamicObject fiber, final DynamicObject block) {
@@ -60,6 +70,15 @@ public void run() {
});
thread.setName(name);
thread.start();

// Wait for full initialization of the new fiber
final CountDownLatch initializedLatch = Layouts.FIBER.getInitializedLatch(fiber);
try {
initializedLatch.await();
} catch (InterruptedException e) {
// Nobody is allowed to have a reference to this Thread yet so this should not happen
throw new UnsupportedOperationException(e);
}
}

private static void handleFiberExceptions(final RubyContext context, final DynamicObject fiber, final DynamicObject block) {
@@ -111,6 +130,8 @@ public static void start(RubyContext context, DynamicObject fiber) {
context.getThreadManager().initializeCurrentThread(Layouts.FIBER.getRubyThread(fiber));
Layouts.THREAD.getFiberManager(Layouts.FIBER.getRubyThread(fiber)).registerFiber(fiber);
context.getSafepointManager().enterThread();
// fully initialized
Layouts.FIBER.getInitializedLatch(fiber).countDown();
}

// Only used by the main thread which cannot easily wrap everything inside a try/finally.
Original file line number Diff line number Diff line change
@@ -70,6 +70,15 @@ public void run() {
ThreadNodes.run(thread, context, currentNode, info, task);
}
}).start();

// Wait for full initialization of the new thread
final CountDownLatch initializedLatch = Layouts.FIBER.getInitializedLatch(Layouts.THREAD.getFiberManager(thread).getRootFiber());
try {
initializedLatch.await();
} catch (InterruptedException e) {
// Nobody is allowed to have a reference to this Thread yet so this should not happen
throw new UnsupportedOperationException(e);
}
}

public static void run(DynamicObject thread, final RubyContext context, Node currentNode, String info, Runnable task) {
@@ -162,6 +171,10 @@ public KillNode(RubyContext context, SourceSection sourceSection) {
@Specialization
public DynamicObject kill(final DynamicObject rubyThread) {
final Thread toKill = Layouts.THREAD.getThread(rubyThread);
if (toKill == null) {
// Already dead
return rubyThread;
}

getContext().getSafepointManager().pauseThreadAndExecuteLater(toKill, this, new SafepointAction() {
@Override
Original file line number Diff line number Diff line change
@@ -11,12 +11,14 @@

import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.object.DynamicObjectFactory;

import org.jruby.truffle.nodes.core.FiberNodes;
import org.jruby.truffle.om.dsl.api.Layout;
import org.jruby.truffle.om.dsl.api.Nullable;
import org.jruby.truffle.om.dsl.api.Volatile;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;

@Layout
public interface FiberLayout extends BasicObjectLayout {
@@ -26,6 +28,7 @@ DynamicObjectFactory createFiberShape(DynamicObject logicalClass,

DynamicObject createFiber(DynamicObjectFactory factory,
boolean rootFiber,
CountDownLatch initializedLatch,
BlockingQueue<FiberNodes.FiberMessage> messageQueue,
DynamicObject rubyThread,
@Nullable String name,
@@ -37,6 +40,8 @@ DynamicObject createFiber(DynamicObjectFactory factory,

boolean getRootFiber(DynamicObject object);

CountDownLatch getInitializedLatch(DynamicObject object);

BlockingQueue<FiberNodes.FiberMessage> getMessageQueue(DynamicObject object);

DynamicObject getRubyThread(DynamicObject object);