-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Truffle] Add ThreadGroup layout and nodes
- 9.4.12.0
- 9.4.11.0
- 9.4.10.0
- 9.4.9.0
- 9.4.8.0
- 9.4.7.0
- 9.4.6.0
- 9.4.5.0
- 9.4.4.0
- 9.4.3.0
- 9.4.2.0
- 9.4.1.0
- 9.4.0.0
- 9.3.15.0
- 9.3.14.0
- 9.3.13.0
- 9.3.12.0
- 9.3.11.0
- 9.3.10.0
- 9.3.9.0
- 9.3.8.0
- 9.3.7.0
- 9.3.6.0
- 9.3.5.0
- 9.3.4.0
- 9.3.3.0
- 9.3.2.0
- 9.3.1.0
- 9.3.0.0
- 9.2.21.0
- 9.2.20.1
- 9.2.20.0
- 9.2.19.0
- 9.2.18.0
- 9.2.17.0
- 9.2.16.0
- 9.2.15.0
- 9.2.14.0
- 9.2.13.0
- 9.2.12.0
- 9.2.11.1
- 9.2.11.0
- 9.2.10.0
- 9.2.9.0
- 9.2.8.0
- 9.2.7.0
- 9.2.6.0
- 9.2.5.0
- 9.2.4.1
- 9.2.4.0
- 9.2.3.0
- 9.2.2.0
- 9.2.1.0
- 9.2.0.0
- 9.1.17.0
- 9.1.16.0
- 9.1.15.0
- 9.1.14.0
- 9.1.13.0
- 9.1.12.0
- 9.1.11.0
- 9.1.10.0
- 9.1.9.0
- 9.1.8.0
- 9.1.7.0
- 9.1.6.0
Brandon Fish
committed
Aug 24, 2016
1 parent
06f447e
commit efe32c0
Showing
13 changed files
with
200 additions
and
24 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
truffle/src/main/java/org/jruby/truffle/core/thread/ThreadGroupLayout.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.jruby.truffle.core.thread; | ||
|
||
import com.oracle.truffle.api.object.DynamicObject; | ||
import com.oracle.truffle.api.object.DynamicObjectFactory; | ||
import com.oracle.truffle.api.object.dsl.Layout; | ||
import org.jruby.truffle.core.basicobject.BasicObjectLayout; | ||
|
||
@Layout | ||
public interface ThreadGroupLayout extends BasicObjectLayout { | ||
|
||
DynamicObjectFactory createThreadGroupShape( | ||
DynamicObject logicalClass, | ||
DynamicObject metaClass); | ||
|
||
DynamicObject createThreadGroup( | ||
DynamicObjectFactory factory, | ||
boolean enclosed); | ||
|
||
boolean getEnclosed(DynamicObject object); | ||
|
||
void setEnclosed(DynamicObject object, boolean value); | ||
|
||
} |
120 changes: 120 additions & 0 deletions
120
truffle/src/main/java/org/jruby/truffle/core/thread/ThreadGroupNodes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package org.jruby.truffle.core.thread; | ||
|
||
import com.oracle.truffle.api.dsl.Specialization; | ||
import com.oracle.truffle.api.object.DynamicObject; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.Layouts; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.builtins.CoreClass; | ||
import org.jruby.truffle.builtins.CoreMethod; | ||
import org.jruby.truffle.builtins.CoreMethodArrayArgumentsNode; | ||
import org.jruby.truffle.language.control.RaiseException; | ||
import org.jruby.truffle.language.objects.AllocateObjectNode; | ||
import org.jruby.truffle.language.objects.IsFrozenNode; | ||
import org.jruby.truffle.language.objects.IsFrozenNodeGen; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@CoreClass("ThreadGroup") | ||
public abstract class ThreadGroupNodes { | ||
|
||
@CoreMethod(names = "allocate", constructor = true) | ||
public abstract static class AllocateNode extends CoreMethodArrayArgumentsNode { | ||
|
||
@Child private AllocateObjectNode allocateObjectNode; | ||
|
||
public AllocateNode(RubyContext context, SourceSection sourceSection) { | ||
super(context, sourceSection); | ||
allocateObjectNode = AllocateObjectNode.create(); | ||
} | ||
|
||
@Specialization | ||
public DynamicObject allocateThreadGroup(DynamicObject rubyClass) { | ||
return allocateObjectNode.allocate(rubyClass, false); | ||
} | ||
|
||
} | ||
|
||
@CoreMethod(names = "enclose") | ||
public abstract static class EncloseNode extends CoreMethodArrayArgumentsNode { | ||
|
||
@Specialization | ||
public DynamicObject enclose(DynamicObject group) { | ||
Layouts.THREAD_GROUP.setEnclosed(group, true); | ||
return group; | ||
} | ||
|
||
} | ||
|
||
@CoreMethod(names = "enclosed?") | ||
public abstract static class EnclosedNode extends CoreMethodArrayArgumentsNode { | ||
|
||
@Specialization | ||
public boolean enclosed(DynamicObject group) { | ||
return Layouts.THREAD_GROUP.getEnclosed(group); | ||
} | ||
|
||
} | ||
|
||
@CoreMethod(names = "list") | ||
public abstract static class ListNode extends CoreMethodArrayArgumentsNode { | ||
|
||
@Specialization | ||
public DynamicObject list(DynamicObject group) { | ||
final Object[] threads = getContext().getThreadManager().getThreadList(); | ||
List<Object> results = new ArrayList<>(); | ||
for (Object thread : threads) { | ||
if (Layouts.THREAD.getThreadGroup((DynamicObject) thread) == group) { | ||
results.add(thread); | ||
} | ||
} | ||
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), results.toArray(), results.size()); | ||
} | ||
|
||
} | ||
|
||
@CoreMethod(names = "add", required = 1) | ||
public abstract static class AddNode extends CoreMethodArrayArgumentsNode { | ||
|
||
@Child private IsFrozenNode isFrozenToNode; | ||
@Child private IsFrozenNode isFrozenFromNode; | ||
|
||
public AddNode(RubyContext context, SourceSection sourceSection) { | ||
isFrozenToNode = IsFrozenNodeGen.create(context, sourceSection, null); | ||
isFrozenFromNode = IsFrozenNodeGen.create(context, sourceSection, null); | ||
} | ||
|
||
@Specialization | ||
public DynamicObject add(DynamicObject toGroup, DynamicObject thread) { | ||
|
||
|
||
if (isFrozenToNode.executeIsFrozen(toGroup)) { | ||
throw new RaiseException(coreExceptions().threadErrorFrozenToThreadGroup(this)); | ||
} | ||
|
||
if (Layouts.THREAD_GROUP.getEnclosed(toGroup)) { | ||
throw new RaiseException(coreExceptions().threadErrorToEnclosedThreadGroup(this)); | ||
} | ||
|
||
final DynamicObject fromGroup = Layouts.THREAD.getThreadGroup(thread); | ||
|
||
if (fromGroup == null) { | ||
return nil(); | ||
} | ||
|
||
if (isFrozenFromNode.executeIsFrozen(fromGroup)) { | ||
throw new RaiseException(coreExceptions().threadErrorFrozenFromThreadGroup(this)); | ||
} | ||
|
||
if (Layouts.THREAD_GROUP.getEnclosed(fromGroup)) { | ||
throw new RaiseException(coreExceptions().threadErrorFromEnclosedThreadGroup(this)); | ||
} | ||
Layouts.THREAD.setThreadGroup(thread, toGroup); | ||
return toGroup; | ||
} | ||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters