Skip to content

Commit

Permalink
Showing 32 changed files with 148 additions and 187 deletions.
8 changes: 0 additions & 8 deletions truffle/src/main/java/org/jruby/truffle/nodes/RubyNode.java
Original file line number Diff line number Diff line change
@@ -191,14 +191,6 @@ protected DynamicObject createString(ByteList bytes) {
return StringNodes.createString(getContext().getCoreLibrary().getStringFactory(), bytes);
}

protected DynamicObject createEmptyArray() {
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);
}

protected DynamicObject createArrayWith(Object... store) {
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), store, store.length);
}

protected DynamicObject createArray(Object store, int size) {
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), store, size);
}
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.array.ArrayUtils;
import org.jruby.truffle.runtime.layouts.Layouts;

/**
* Read the rest of arguments after a certain point into an array.
@@ -41,8 +42,6 @@ public ReadRestArgumentNode(RubyContext context, SourceSection sourceSection, in

@Override
public Object execute(VirtualFrame frame) {
final DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();

int count = RubyArguments.getUserArgumentsCount(frame.getArguments());

int endIndex = count + negativeEndIndex;
@@ -57,19 +56,26 @@ public Object execute(VirtualFrame frame) {

final int length = endIndex - startIndex;

final Object resultStore;
final int resultLength;

if (startIndex == 0) {
final Object[] arguments = RubyArguments.extractUserArguments(frame.getArguments());
return ArrayNodes.createGeneralArray(arrayClass, arguments, length);
resultStore = arguments;
resultLength = length;
} else {
if (startIndex >= endIndex) {
noArgumentsLeftProfile.enter();
return ArrayNodes.createGeneralArray(arrayClass, null, 0);
resultStore = null;
resultLength = 0;
} else {
subsetOfArgumentsProfile.enter();
final Object[] arguments = RubyArguments.extractUserArguments(frame.getArguments());
// TODO(CS): risk here of widening types too much - always going to be Object[] - does seem to be something that does happen
return ArrayNodes.createGeneralArray(arrayClass, ArrayUtils.extractRange(arguments, startIndex, endIndex), length);
resultStore = ArrayUtils.extractRange(arguments, startIndex, endIndex);
resultLength = length;
}
}

return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), resultStore, resultLength);
}
}
Original file line number Diff line number Diff line change
@@ -17,13 +17,13 @@
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.nodes.dispatch.DispatchNode;
import org.jruby.truffle.nodes.dispatch.MissingBehavior;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.layouts.Layouts;

/*
* TODO(CS): could probably unify this with SplatCastNode with some final configuration options.
@@ -81,10 +81,10 @@ public DynamicObject castArray(DynamicObject array) {
public Object cast(Object nil) {
switch (nilBehavior) {
case EMPTY_ARRAY:
return createEmptyArray();
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);

case ARRAY_WITH_NIL:
return ArrayNodes.createGeneralArray(getContext().getCoreLibrary().getArrayClass(), new Object[]{nil()}, 1);
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), new Object[]{nil()}, 1);

case NIL:
return nil;
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.layouts.Layouts;

@NodeChild(value = "child", type = RubyNode.class)
public abstract class SingleValueCastNode extends RubyNode {
@@ -41,8 +42,7 @@ protected Object castSingle(Object[] args) {
@TruffleBoundary
@Specialization(guards = { "!noArguments(args)", "!singleArgument(args)" })
protected DynamicObject castMany(Object[] args) {
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
return ArrayNodes.createGeneralArray(arrayClass, args, args.length);
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), args, args.length);
}

protected boolean noArguments(Object[] args) {
Original file line number Diff line number Diff line change
@@ -19,13 +19,13 @@
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.array.ArrayDupNode;
import org.jruby.truffle.nodes.core.array.ArrayDupNodeGen;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.nodes.dispatch.DispatchNode;
import org.jruby.truffle.nodes.dispatch.MissingBehavior;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.layouts.Layouts;

/**
* Splat as used to cast a value to an array if it isn't already, as in {@code *value}.
@@ -64,10 +64,10 @@ public SplatCastNode(RubyContext context, SourceSection sourceSection, NilBehavi
public DynamicObject splat(Object nil) {
switch (nilBehavior) {
case EMPTY_ARRAY:
return createEmptyArray();
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);

case ARRAY_WITH_NIL:
return ArrayNodes.createGeneralArray(getContext().getCoreLibrary().getArrayClass(), new Object[]{nil()}, 1);
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), new Object[]{nil()}, 1);

default: {
throw new UnsupportedOperationException();
@@ -101,15 +101,15 @@ public DynamicObject splat(VirtualFrame frame, Object object) {
return (DynamicObject) array;
} else if (array == nil() || array == DispatchNode.MISSING) {
CompilerDirectives.transferToInterpreter();
return ArrayNodes.createGeneralArray(getContext().getCoreLibrary().getArrayClass(), new Object[]{object}, 1);
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), new Object[]{object}, 1);
} else {
throw new RaiseException(getContext().getCoreLibrary().typeErrorCantConvertTo(
object, getContext().getCoreLibrary().getArrayClass(), method, array, this)
);
}
}

return ArrayNodes.createGeneralArray(getContext().getCoreLibrary().getArrayClass(), new Object[]{object}, 1);
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), new Object[]{object}, 1);
}

}
Original file line number Diff line number Diff line change
@@ -260,7 +260,7 @@ public LocalVariablesNode(RubyContext context, SourceSection sourceSection) {
@TruffleBoundary
@Specialization
public DynamicObject localVariables(DynamicObject binding) {
final DynamicObject array = createEmptyArray();
final DynamicObject array = Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);

MaterializedFrame frame = Layouts.BINDING.getFrame(binding);

Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.nodes.objectstorage.ReadHeadObjectFieldNode;
import org.jruby.truffle.runtime.NotProvided;
import org.jruby.truffle.runtime.RubyCallStack;
@@ -45,8 +44,7 @@ public static DynamicObject asRubyStringArray(DynamicObject exception) {
array[n] = StringNodes.createString(Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(exception)).getContext().getCoreLibrary().getStringClass(), lines.get(n));
}

DynamicObject arrayClass = Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(exception)).getContext().getCoreLibrary().getArrayClass();
return ArrayNodes.createGeneralArray(arrayClass, array, array.length);
return Layouts.ARRAY.createArray(Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(exception)).getContext().getCoreLibrary().getArrayFactory(), array, array.length);
}

public static void setMessage(DynamicObject exception, Object message) {
Original file line number Diff line number Diff line change
@@ -1053,7 +1053,7 @@ public DynamicObject instanceVariables(DynamicObject self) {

Arrays.sort(instanceVariableNames);

final DynamicObject array = createEmptyArray();
final DynamicObject array = Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);

for (Object name : instanceVariableNames) {
if (name instanceof String) {
@@ -1197,7 +1197,7 @@ public LocalVariablesNode(RubyContext context, SourceSection sourceSection) {
public DynamicObject localVariables() {
CompilerDirectives.transferToInterpreter();

final DynamicObject array = createEmptyArray();
final DynamicObject array = Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);

for (Object name : RubyCallStack.getCallerFrame(getContext()).getFrame(FrameInstance.FrameAccess.READ_ONLY, false).getFrameDescriptor().getIdentifiers()) {
if (name instanceof String) {
@@ -1282,9 +1282,8 @@ public DynamicObject methodsRegular(VirtualFrame frame, Object self, boolean reg
final DynamicObject metaClass = metaClassNode.executeMetaClass(frame, self);

CompilerDirectives.transferToInterpreter();
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
Object[] objects = Layouts.MODULE.getFields(metaClass).filterMethodsOnObject(regular, MethodFilter.PUBLIC_PROTECTED).toArray();
return ArrayNodes.createGeneralArray(arrayClass, objects, objects.length);
return createArray(objects, objects.length);
}

@Specialization(guards = "!regular")
@@ -1340,9 +1339,8 @@ public DynamicObject privateMethods(VirtualFrame frame, Object self, boolean inc
DynamicObject metaClass = metaClassNode.executeMetaClass(frame, self);

CompilerDirectives.transferToInterpreter();
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
Object[] objects = Layouts.MODULE.getFields(metaClass).filterMethodsOnObject(includeAncestors, MethodFilter.PRIVATE).toArray();
return ArrayNodes.createGeneralArray(arrayClass, objects, objects.length);
return createArray(objects, objects.length);
}

}
@@ -1388,9 +1386,8 @@ public DynamicObject protectedMethods(VirtualFrame frame, Object self, boolean i
final DynamicObject metaClass = metaClassNode.executeMetaClass(frame, self);

CompilerDirectives.transferToInterpreter();
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
Object[] objects = Layouts.MODULE.getFields(metaClass).filterMethodsOnObject(includeAncestors, MethodFilter.PROTECTED).toArray();
return ArrayNodes.createGeneralArray(arrayClass, objects, objects.length);
return createArray(objects, objects.length);
}

}
@@ -1419,9 +1416,8 @@ public DynamicObject publicMethods(VirtualFrame frame, Object self, boolean incl
final DynamicObject metaClass = metaClassNode.executeMetaClass(frame, self);

CompilerDirectives.transferToInterpreter();
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
Object[] objects = Layouts.MODULE.getFields(metaClass).filterMethodsOnObject(includeAncestors, MethodFilter.PUBLIC).toArray();
return ArrayNodes.createGeneralArray(arrayClass, objects, objects.length);
return createArray(objects, objects.length);
}

}
@@ -1757,13 +1753,12 @@ public DynamicObject singletonMethods(VirtualFrame frame, Object self, boolean i
final DynamicObject metaClass = metaClassNode.executeMetaClass(frame, self);

if (!Layouts.CLASS.getIsSingleton(metaClass)) {
return createEmptyArray();
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);
}

CompilerDirectives.transferToInterpreter();
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
Object[] objects = Layouts.MODULE.getFields(metaClass).filterSingletonMethods(includeAncestors, MethodFilter.PUBLIC_PROTECTED).toArray();
return ArrayNodes.createGeneralArray(arrayClass, objects, objects.length);
return createArray(objects, objects.length);
}

}
Original file line number Diff line number Diff line change
@@ -326,9 +326,8 @@ public CapturesNode(RubyContext context, SourceSection sourceSection) {
public DynamicObject toA(DynamicObject matchData) {
CompilerDirectives.transferToInterpreter();

DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
Object[] objects = getCaptures(matchData);
return ArrayNodes.createGeneralArray(arrayClass, objects, objects.length);
return createArray(objects, objects.length);
}
}

@@ -448,9 +447,8 @@ public ToANode(RubyContext context, SourceSection sourceSection) {
public DynamicObject toA(DynamicObject matchData) {
CompilerDirectives.transferToInterpreter();

DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
Object[] objects = Arrays.copyOf(Layouts.MATCH_DATA.getValues(matchData), Layouts.MATCH_DATA.getValues(matchData).length);
return ArrayNodes.createGeneralArray(arrayClass, objects, objects.length);
return createArray(objects, objects.length);
}
}

Original file line number Diff line number Diff line change
@@ -202,9 +202,8 @@ public Object sourceLocation(DynamicObject method) {
return nil();
} else {
DynamicObject file = createString(sourceSection.getSource().getName());
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
Object[] objects = new Object[]{file, sourceSection.getStartLine()};
return ArrayNodes.createGeneralArray(arrayClass, objects, objects.length);
return createArray(objects, objects.length);
}
}

Loading

0 comments on commit dd2ebc8

Please sign in to comment.