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: dec25349f989
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 65f0175a97f4
Choose a head ref
  • 4 commits
  • 3 files changed
  • 1 contributor

Commits on Jun 13, 2016

  1. Copy the full SHA
    d3325f8 View commit details
  2. Copy the full SHA
    a5ef069 View commit details
  3. Copy the full SHA
    38b41a4 View commit details
  4. Copy the full SHA
    65f0175 View commit details
7 changes: 5 additions & 2 deletions truffle/src/main/java/org/jruby/truffle/RubyContext.java
Original file line number Diff line number Diff line change
@@ -147,14 +147,17 @@ public RubyContext(Ruby jrubyRuntime, TruffleLanguage.Env env) {

// Load the nodes

org.jruby.Main.printTruffleTimeMetric("before-load-primitives");
coreLibrary.addPrimitives();
org.jruby.Main.printTruffleTimeMetric("after-load-primitives");

org.jruby.Main.printTruffleTimeMetric("before-load-nodes");
coreLibrary.addCoreMethods();
primitiveManager.addAnnotatedPrimitives();
org.jruby.Main.printTruffleTimeMetric("after-load-nodes");

// Load the reset of the core library

coreLibrary.initializeAfterBasicMethodsAdded();
coreLibrary.loadRubyCore();

// Load other subsystems

Original file line number Diff line number Diff line change
@@ -11,33 +11,10 @@

import com.oracle.truffle.api.dsl.GeneratedBy;
import com.oracle.truffle.api.dsl.NodeFactory;
import org.jruby.truffle.core.ObjectNodesFactory;
import org.jruby.truffle.core.VMPrimitiveNodesFactory;
import org.jruby.truffle.core.array.ArrayNodesFactory;
import org.jruby.truffle.core.dir.DirNodesFactory;
import org.jruby.truffle.core.encoding.EncodingConverterNodesFactory;
import org.jruby.truffle.core.encoding.EncodingNodesFactory;
import org.jruby.truffle.core.exception.ExceptionNodesFactory;
import org.jruby.truffle.core.numeric.BignumNodesFactory;
import org.jruby.truffle.core.numeric.FixnumNodesFactory;
import org.jruby.truffle.core.numeric.FloatNodesFactory;
import org.jruby.truffle.core.rubinius.IOBufferPrimitiveNodesFactory;
import org.jruby.truffle.core.rubinius.IOPrimitiveNodesFactory;
import org.jruby.truffle.core.rubinius.NativeFunctionPrimitiveNodesFactory;
import org.jruby.truffle.core.rubinius.RandomizerPrimitiveNodesFactory;
import org.jruby.truffle.core.rubinius.RegexpPrimitiveNodesFactory;
import org.jruby.truffle.core.rubinius.StatPrimitiveNodesFactory;
import org.jruby.truffle.core.rubinius.UndefinedPrimitiveNodes;
import org.jruby.truffle.core.rubinius.UndefinedPrimitiveNodesFactory;
import org.jruby.truffle.core.rubinius.WeakRefPrimitiveNodesFactory;
import org.jruby.truffle.core.string.StringNodesFactory;
import org.jruby.truffle.core.symbol.SymbolNodesFactory;
import org.jruby.truffle.core.thread.ThreadNodesFactory;
import org.jruby.truffle.core.time.TimeNodesFactory;
import org.jruby.truffle.extra.ffi.PointerPrimitiveNodesFactory;
import org.jruby.truffle.language.RubyNode;

import java.util.ArrayList;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -59,41 +36,14 @@ public PrimitiveNodeConstructor getPrimitive(String name) {
return constructor;
}

public void addAnnotatedPrimitives() {
final List<NodeFactory<? extends RubyNode>> nodeFactories = new ArrayList<>();

nodeFactories.addAll(VMPrimitiveNodesFactory.getFactories());
nodeFactories.addAll(ObjectNodesFactory.getFactories());
nodeFactories.addAll(TimeNodesFactory.getFactories());
nodeFactories.addAll(StringNodesFactory.getFactories());
nodeFactories.addAll(SymbolNodesFactory.getFactories());
nodeFactories.addAll(FixnumNodesFactory.getFactories());
nodeFactories.addAll(BignumNodesFactory.getFactories());
nodeFactories.addAll(FloatNodesFactory.getFactories());
nodeFactories.addAll(EncodingNodesFactory.getFactories());
nodeFactories.addAll(EncodingConverterNodesFactory.getFactories());
nodeFactories.addAll(RegexpPrimitiveNodesFactory.getFactories());
nodeFactories.addAll(RandomizerPrimitiveNodesFactory.getFactories());
nodeFactories.addAll(ArrayNodesFactory.getFactories());
nodeFactories.addAll(StatPrimitiveNodesFactory.getFactories());
nodeFactories.addAll(PointerPrimitiveNodesFactory.getFactories());
nodeFactories.addAll(NativeFunctionPrimitiveNodesFactory.getFactories());
nodeFactories.addAll(DirNodesFactory.getFactories());
nodeFactories.addAll(IOPrimitiveNodesFactory.getFactories());
nodeFactories.addAll(IOBufferPrimitiveNodesFactory.getFactories());
nodeFactories.addAll(ExceptionNodesFactory.getFactories());
nodeFactories.addAll(ThreadNodesFactory.getFactories());
nodeFactories.addAll(WeakRefPrimitiveNodesFactory.getFactories());

// This comes last as a catch-all
nodeFactories.addAll(UndefinedPrimitiveNodesFactory.getFactories());

public void addPrimitiveNodes(List<? extends NodeFactory<? extends RubyNode>> nodeFactories) {
for (NodeFactory<? extends RubyNode> nodeFactory : nodeFactories) {
final GeneratedBy generatedBy = nodeFactory.getClass().getAnnotation(GeneratedBy.class);
final Class<?> nodeClass = generatedBy.value();
final Primitive annotation = nodeClass.getAnnotation(Primitive.class);

if (annotation != null) {
primitives.putIfAbsent(annotation.name(), new PrimitiveNodeConstructor(annotation, nodeFactory));
primitives.put(annotation.name(), new PrimitiveNodeConstructor(annotation, nodeFactory));
}
}
}
110 changes: 81 additions & 29 deletions truffle/src/main/java/org/jruby/truffle/core/CoreLibrary.java
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.TruffleOptions;
import com.oracle.truffle.api.dsl.GeneratedBy;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.interop.java.JavaInterop;
import com.oracle.truffle.api.object.DynamicObject;
@@ -31,6 +33,9 @@
import org.jruby.truffle.Layouts;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.builtins.CoreMethodNodeManager;
import org.jruby.truffle.builtins.Primitive;
import org.jruby.truffle.builtins.PrimitiveManager;
import org.jruby.truffle.builtins.PrimitiveNodeConstructor;
import org.jruby.truffle.core.array.ArrayNodes;
import org.jruby.truffle.core.array.ArrayNodesFactory;
import org.jruby.truffle.core.array.TruffleArrayNodesFactory;
@@ -39,6 +44,7 @@
import org.jruby.truffle.core.binding.TruffleBindingNodesFactory;
import org.jruby.truffle.core.bool.FalseClassNodesFactory;
import org.jruby.truffle.core.bool.TrueClassNodesFactory;
import org.jruby.truffle.core.dir.DirNodesFactory;
import org.jruby.truffle.core.encoding.EncodingConverterNodesFactory;
import org.jruby.truffle.core.encoding.EncodingNodes;
import org.jruby.truffle.core.encoding.EncodingNodesFactory;
@@ -70,7 +76,15 @@
import org.jruby.truffle.core.rope.TruffleRopesNodesFactory;
import org.jruby.truffle.core.rubinius.AtomicReferenceNodesFactory;
import org.jruby.truffle.core.rubinius.ByteArrayNodesFactory;
import org.jruby.truffle.core.rubinius.IOBufferPrimitiveNodesFactory;
import org.jruby.truffle.core.rubinius.IOPrimitiveNodesFactory;
import org.jruby.truffle.core.rubinius.NativeFunctionPrimitiveNodesFactory;
import org.jruby.truffle.core.rubinius.RandomizerPrimitiveNodesFactory;
import org.jruby.truffle.core.rubinius.RegexpPrimitiveNodesFactory;
import org.jruby.truffle.core.rubinius.RubiniusTypeNodesFactory;
import org.jruby.truffle.core.rubinius.StatPrimitiveNodesFactory;
import org.jruby.truffle.core.rubinius.UndefinedPrimitiveNodesFactory;
import org.jruby.truffle.core.rubinius.WeakRefPrimitiveNodesFactory;
import org.jruby.truffle.core.string.StringNodesFactory;
import org.jruby.truffle.core.string.StringOperations;
import org.jruby.truffle.core.symbol.SymbolNodesFactory;
@@ -83,6 +97,7 @@
import org.jruby.truffle.extra.AttachmentsInternalNodesFactory;
import org.jruby.truffle.extra.TruffleGraalNodesFactory;
import org.jruby.truffle.extra.TrufflePosixNodesFactory;
import org.jruby.truffle.extra.ffi.PointerPrimitiveNodesFactory;
import org.jruby.truffle.gem.bcrypt.BCryptNodesFactory;
import org.jruby.truffle.interop.CExtNodesFactory;
import org.jruby.truffle.interop.InteropNodesFactory;
@@ -118,8 +133,10 @@
import org.jruby.util.cli.OutputStrings;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
@@ -703,12 +720,53 @@ public void initialize() {
initializeSignalConstants();
}

public void addPrimitives() {
final PrimitiveManager primitiveManager = context.getPrimitiveManager();

ForkJoinPool.commonPool().invokeAll(Arrays.asList(() -> {
primitiveManager.addPrimitiveNodes(SymbolNodesFactory.getFactories());
primitiveManager.addPrimitiveNodes(FixnumNodesFactory.getFactories());
primitiveManager.addPrimitiveNodes(BignumNodesFactory.getFactories());
primitiveManager.addPrimitiveNodes(FloatNodesFactory.getFactories());
primitiveManager.addPrimitiveNodes(VMPrimitiveNodesFactory.getFactories());
return null;
}, () -> {
primitiveManager.addPrimitiveNodes(EncodingNodesFactory.getFactories());
primitiveManager.addPrimitiveNodes(EncodingConverterNodesFactory.getFactories());
primitiveManager.addPrimitiveNodes(RegexpPrimitiveNodesFactory.getFactories());
primitiveManager.addPrimitiveNodes(RandomizerPrimitiveNodesFactory.getFactories());
primitiveManager.addPrimitiveNodes(ObjectNodesFactory.getFactories());
return null;
}, () -> {
primitiveManager.addPrimitiveNodes(ArrayNodesFactory.getFactories());
primitiveManager.addPrimitiveNodes(StatPrimitiveNodesFactory.getFactories());
primitiveManager.addPrimitiveNodes(PointerPrimitiveNodesFactory.getFactories());
primitiveManager.addPrimitiveNodes(NativeFunctionPrimitiveNodesFactory.getFactories());
return null;
}, () -> {
primitiveManager.addPrimitiveNodes(DirNodesFactory.getFactories());
primitiveManager.addPrimitiveNodes(IOPrimitiveNodesFactory.getFactories());
primitiveManager.addPrimitiveNodes(IOBufferPrimitiveNodesFactory.getFactories());
primitiveManager.addPrimitiveNodes(ExceptionNodesFactory.getFactories());
return null;
}, () -> {
primitiveManager.addPrimitiveNodes(ThreadNodesFactory.getFactories());
primitiveManager.addPrimitiveNodes(WeakRefPrimitiveNodesFactory.getFactories());
primitiveManager.addPrimitiveNodes(TimeNodesFactory.getFactories());
primitiveManager.addPrimitiveNodes(StringNodesFactory.getFactories());

// Catch all
primitiveManager.addPrimitiveNodes(UndefinedPrimitiveNodesFactory.getFactories());

return null;
}));
}

public void addCoreMethods() {
arrayMinBlock = new ArrayNodes.MinBlock(context);
arrayMaxBlock = new ArrayNodes.MaxBlock(context);

// Bring in core method nodes
CoreMethodNodeManager coreMethodNodeManager = new CoreMethodNodeManager(context, node.getSingletonClassNode());
final CoreMethodNodeManager coreMethodNodeManager = new CoreMethodNodeManager(context, node.getSingletonClassNode());

ForkJoinPool.commonPool().invokeAll(Arrays.asList(() -> {
coreMethodNodeManager.addCoreMethodNodes(ArrayNodesFactory.getFactories());
@@ -828,7 +886,26 @@ private void initializeGlobalVariables() {
}

private void initializeConstants() {
// Set constants
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_CHAR", RubiniusTypes.TYPE_CHAR);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_UCHAR", RubiniusTypes.TYPE_UCHAR);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_BOOL", RubiniusTypes.TYPE_BOOL);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_SHORT", RubiniusTypes.TYPE_SHORT);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_USHORT", RubiniusTypes.TYPE_USHORT);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_INT", RubiniusTypes.TYPE_INT);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_UINT", RubiniusTypes.TYPE_UINT);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_LONG", RubiniusTypes.TYPE_LONG);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_ULONG", RubiniusTypes.TYPE_ULONG);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_LL", RubiniusTypes.TYPE_LL);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_ULL", RubiniusTypes.TYPE_ULL);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_FLOAT", RubiniusTypes.TYPE_FLOAT);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_DOUBLE", RubiniusTypes.TYPE_DOUBLE);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_PTR", RubiniusTypes.TYPE_PTR);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_VOID", RubiniusTypes.TYPE_VOID);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_STRING", RubiniusTypes.TYPE_STRING);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_STRPTR", RubiniusTypes.TYPE_STRPTR);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_CHARARR", RubiniusTypes.TYPE_CHARARR);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_ENUM", RubiniusTypes.TYPE_ENUM);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_VARARGS", RubiniusTypes.TYPE_VARARGS);

Layouts.MODULE.getFields(objectClass).setConstant(context, node, "RUBY_VERSION", StringOperations.createString(context, StringOperations.encodeRope(Constants.RUBY_VERSION, UTF8Encoding.INSTANCE)));
Layouts.MODULE.getFields(objectClass).setConstant(context, node, "JRUBY_VERSION", StringOperations.createString(context, StringOperations.encodeRope(Constants.VERSION, UTF8Encoding.INSTANCE)));
@@ -918,9 +995,7 @@ private DynamicObject defineModule(DynamicObject lexicalParent, String name) {
return ModuleNodes.createModule(context, moduleClass, lexicalParent, name, node);
}

public void initializeAfterBasicMethodsAdded() {
initializeRubiniusFFI();

public void loadRubyCore() {
// Load Ruby core

try {
@@ -1005,29 +1080,6 @@ public void initializePostBoot() {
}
}

private void initializeRubiniusFFI() {
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_CHAR", RubiniusTypes.TYPE_CHAR);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_UCHAR", RubiniusTypes.TYPE_UCHAR);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_BOOL", RubiniusTypes.TYPE_BOOL);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_SHORT", RubiniusTypes.TYPE_SHORT);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_USHORT", RubiniusTypes.TYPE_USHORT);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_INT", RubiniusTypes.TYPE_INT);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_UINT", RubiniusTypes.TYPE_UINT);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_LONG", RubiniusTypes.TYPE_LONG);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_ULONG", RubiniusTypes.TYPE_ULONG);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_LL", RubiniusTypes.TYPE_LL);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_ULL", RubiniusTypes.TYPE_ULL);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_FLOAT", RubiniusTypes.TYPE_FLOAT);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_DOUBLE", RubiniusTypes.TYPE_DOUBLE);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_PTR", RubiniusTypes.TYPE_PTR);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_VOID", RubiniusTypes.TYPE_VOID);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_STRING", RubiniusTypes.TYPE_STRING);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_STRPTR", RubiniusTypes.TYPE_STRPTR);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_CHARARR", RubiniusTypes.TYPE_CHARARR);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_ENUM", RubiniusTypes.TYPE_ENUM);
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_VARARGS", RubiniusTypes.TYPE_VARARGS);
}

public void initializeEncodingConstants() {
getContext().getJRubyRuntime().getEncodingService().defineEncodings(new EncodingService.EncodingDefinitionVisitor() {
@Override