Skip to content

Commit

Permalink
Showing 10 changed files with 63 additions and 185 deletions.
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/threadgroup/default_tags.txt

This file was deleted.

3 changes: 0 additions & 3 deletions truffle/src/main/java/org/jruby/truffle/Layouts.java
Original file line number Diff line number Diff line change
@@ -86,8 +86,6 @@
import org.jruby.truffle.core.symbol.SymbolLayoutImpl;
import org.jruby.truffle.core.thread.ThreadBacktraceLocationLayout;
import org.jruby.truffle.core.thread.ThreadBacktraceLocationLayoutImpl;
import org.jruby.truffle.core.thread.ThreadGroupLayout;
import org.jruby.truffle.core.thread.ThreadGroupLayoutImpl;
import org.jruby.truffle.core.thread.ThreadLayout;
import org.jruby.truffle.core.thread.ThreadLayoutImpl;
import org.jruby.truffle.core.time.TimeLayout;
@@ -141,7 +139,6 @@ public abstract class Layouts {
public static final SymbolLayout SYMBOL = SymbolLayoutImpl.INSTANCE;
public static final ThreadLayout THREAD = ThreadLayoutImpl.INSTANCE;
public static final ThreadBacktraceLocationLayout THREAD_BACKTRACE_LOCATION = ThreadBacktraceLocationLayoutImpl.INSTANCE;
public static final ThreadGroupLayout THREAD_GROUP = ThreadGroupLayoutImpl.INSTANCE;
public static final TimeLayout TIME = TimeLayoutImpl.INSTANCE;
public static final UnboundMethodLayout UNBOUND_METHOD = UnboundMethodLayoutImpl.INSTANCE;
public static final WeakRefLayout WEAK_REF_LAYOUT = WeakRefLayoutImpl.INSTANCE;
13 changes: 0 additions & 13 deletions truffle/src/main/java/org/jruby/truffle/core/CoreLibrary.java
Original file line number Diff line number Diff line change
@@ -94,7 +94,6 @@
import org.jruby.truffle.core.symbol.SymbolNodesFactory;
import org.jruby.truffle.core.thread.ThreadBacktraceLocationLayoutImpl;
import org.jruby.truffle.core.thread.ThreadBacktraceLocationNodesFactory;
import org.jruby.truffle.core.thread.ThreadGroupNodesFactory;
import org.jruby.truffle.core.thread.ThreadNodesFactory;
import org.jruby.truffle.core.time.TimeNodesFactory;
import org.jruby.truffle.core.tracepoint.TracePointNodesFactory;
@@ -226,8 +225,6 @@ public class CoreLibrary {
private final DynamicObject systemExitClass;
private final DynamicObject threadClass;
private final DynamicObjectFactory threadFactory;
private final DynamicObject threadGroupClass;
private final DynamicObjectFactory threadGroupFactory;
private final DynamicObject threadBacktraceClass;
private final DynamicObject threadBacktraceLocationClass;
private final DynamicObjectFactory threadBacktraceLocationFactory;
@@ -531,11 +528,6 @@ public CoreLibrary(RubyContext context) {
threadFactory = Layouts.THREAD.createThreadShape(threadClass, threadClass);
Layouts.CLASS.setInstanceFactoryUnsafe(threadClass, threadFactory);


threadGroupClass = defineClass("ThreadGroup");
threadGroupFactory = Layouts.THREAD_GROUP.createThreadGroupShape(threadGroupClass, threadGroupClass);
Layouts.CLASS.setInstanceFactoryUnsafe(threadGroupClass, threadGroupFactory);

threadBacktraceClass = defineClass(threadClass, objectClass, "Backtrace");
threadBacktraceLocationClass = defineClass(threadBacktraceClass, objectClass, "Location");
threadBacktraceLocationFactory = ThreadBacktraceLocationLayoutImpl.INSTANCE.createThreadBacktraceLocationShape(threadBacktraceLocationClass, threadBacktraceLocationClass);
@@ -755,7 +747,6 @@ public void addCoreMethods(PrimitiveManager primitiveManager) {
SymbolNodesFactory.getFactories(),
SystemCallErrorNodesFactory.getFactories(),
ThreadBacktraceLocationNodesFactory.getFactories(),
ThreadGroupNodesFactory.getFactories(),
ThreadNodesFactory.getFactories(),
TimeNodesFactory.getFactories(),
TracePointNodesFactory.getFactories(),
@@ -1302,10 +1293,6 @@ public DynamicObjectFactory getThreadFactory() {
return threadFactory;
}

public DynamicObjectFactory getThreadGroupFactory() {
return threadGroupFactory;
}

public DynamicObject getTypeErrorClass() {
return typeErrorClass;
}
Original file line number Diff line number Diff line change
@@ -794,22 +794,6 @@ public DynamicObject threadErrorAlreadyLocked(Node currentNode) {
return threadError("Attempt to unlock a mutex which is locked by another thread", currentNode);
}

public DynamicObject threadErrorFrozenToThreadGroup(Node currentNode) {
return threadError("can't move to the frozen thread group", currentNode);
}

public DynamicObject threadErrorFrozenFromThreadGroup(Node currentNode) {
return threadError("can't move from the frozen thread group", currentNode);
}

public DynamicObject threadErrorToEnclosedThreadGroup(Node currentNode) {
return threadError("can't move to the enclosed thread group", currentNode);
}

public DynamicObject threadErrorFromEnclosedThreadGroup(Node currentNode) {
return threadError("can't move from the enclosed thread group", currentNode);
}

// SecurityError

@TruffleBoundary
Original file line number Diff line number Diff line change
@@ -92,9 +92,7 @@ public synchronized void defineFinalizer(DynamicObject object, Object callable)

if (finalizerThread == null) {
// TODO(CS): should we be running this in a real Ruby thread?

final DynamicObject rootGroup = Layouts.THREAD.getThreadGroup(context.getThreadManager().getRootThread());
finalizerThread = ThreadManager.createRubyThread(context, rootGroup);
finalizerThread = ThreadManager.createRubyThread(context);
ThreadManager.initialize(finalizerThread, context, null, "finalizer", new Runnable() {
@Override
public void run() {

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -49,14 +49,13 @@ public class ThreadManager {

public ThreadManager(RubyContext context) {
this.context = context;
final DynamicObject group = Layouts.THREAD_GROUP.createThreadGroup(context.getCoreLibrary().getThreadGroupFactory(), false);
this.rootThread = createRubyThread(context, group);
this.rootThread = createRubyThread(context);
}

public static final InterruptMode DEFAULT_INTERRUPT_MODE = InterruptMode.IMMEDIATE;
public static final Status DEFAULT_STATUS = Status.RUN;

public static DynamicObject createRubyThread(RubyContext context, DynamicObject group) {
public static DynamicObject createRubyThread(RubyContext context) {
final DynamicObject object = Layouts.THREAD.createThread(
context.getCoreLibrary().getThreadFactory(),
createThreadLocals(context),
@@ -71,7 +70,7 @@ public static DynamicObject createRubyThread(RubyContext context, DynamicObject
null,
new AtomicBoolean(false),
0,
group);
null);

Layouts.THREAD.setFiberManagerUnsafe(object, new FiberManager(context, object)); // Because it is cyclic

Original file line number Diff line number Diff line change
@@ -118,7 +118,12 @@ public abstract static class GroupNode extends CoreMethodArrayArgumentsNode {

@Specialization
public DynamicObject group(DynamicObject thread) {
return Layouts.THREAD.getThreadGroup(thread);
final DynamicObject group = Layouts.THREAD.getThreadGroup(thread);
if (group == null) {
return nil();
} else {
return group;
}
}
}

@@ -528,6 +533,19 @@ public int getPriority(DynamicObject thread, int rubyPriority) {
}
}

@Primitive(name = "thread_set_group", unsafe = UnsafeGroup.THREADS)
public static abstract class ThreadSetGroupPrimitiveNode extends PrimitiveArrayArgumentsNode {
public ThreadSetGroupPrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization(guards = "isRubyThread(thread)")
public DynamicObject setGroup(DynamicObject thread, DynamicObject threadGroup) {
Layouts.THREAD.setThreadGroup(thread, threadGroup);
return threadGroup;
}
}

@Primitive(name = "thread_get_fiber_locals", unsafe = UnsafeGroup.THREADS)
public static abstract class ThreadGetFiberLocalsNode extends PrimitiveArrayArgumentsNode {

40 changes: 40 additions & 0 deletions truffle/src/main/ruby/core/thread.rb
Original file line number Diff line number Diff line change
@@ -60,6 +60,10 @@

class Thread

def initialize
Truffle.invoke_primitive :thread_set_group, self, Thread.current.group
end

# Implementation note: ideally, the recursive_objects
# lookup table would be different per method call.
# Currently it doesn't cause problems, but if ever
@@ -351,3 +355,39 @@ def freeze

end

class ThreadGroup
def initialize
@enclosed = false
end

def enclose
@enclosed = true
end

def enclosed?
@enclosed
end

def add(thread)
raise ThreadError, "can't move to the frozen thread group" if self.frozen?
raise ThreadError, "can't move to the enclosed thread group" if self.enclosed?

from_tg = thread.group
return nil unless from_tg
raise ThreadError, "can't move from the frozen thread group" if from_tg.frozen?
raise ThreadError, "can't move from the enclosed thread group" if from_tg.enclosed?

Truffle.invoke_primitive :thread_set_group, thread, self
self
end

def list
Thread.list.find_all { |th| th.group == self }
end

Default = ThreadGroup.new

end
Truffle.invoke_primitive :thread_set_group, Thread.current, ThreadGroup::Default


0 comments on commit aea26f7

Please sign in to comment.