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: 33768a591c14
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b221938f0212
Choose a head ref
  • 10 commits
  • 69 files changed
  • 4 contributors

Commits on May 29, 2015

  1. Copy the full SHA
    ba06032 View commit details
  2. Copy the full SHA
    3ee92de View commit details
  3. Copy the full SHA
    7d8cdff View commit details
  4. Copy the full SHA
    8af0669 View commit details
  5. [build] cleanup test/pom.rb

    mkristian committed May 29, 2015
    Copy the full SHA
    392d1e0 View commit details
  6. Copy the full SHA
    781a021 View commit details
  7. Copy the full SHA
    4fcc7df View commit details
  8. Copy the full SHA
    3956fba View commit details
  9. Merge branch 'master' into truffle-head

    Conflicts:
    	truffle/src/main/java/org/jruby/truffle/runtime/core/RubyMethod.java
    chrisseaton committed May 29, 2015
    Copy the full SHA
    9ab30f1 View commit details
  10. Copy the full SHA
    b221938 View commit details
Showing with 1,646 additions and 2,688 deletions.
  1. +1 −1 test/mri_truffle.index
  2. +3 −3 test/pom.rb
  3. +0 −1,092 test/pom.xml
  4. +12 −2 truffle/src/main/java/org/jruby/truffle/nodes/RubyGuards.java
  5. +2 −1 truffle/src/main/java/org/jruby/truffle/nodes/arguments/ReadKeywordRestArgumentNode.java
  6. +2 −2 truffle/src/main/java/org/jruby/truffle/nodes/cast/ArrayCastNode.java
  7. +2 −2 truffle/src/main/java/org/jruby/truffle/nodes/cast/SingleValueCastNode.java
  8. +4 −3 truffle/src/main/java/org/jruby/truffle/nodes/cast/SplatCastNode.java
  9. +2 −1 truffle/src/main/java/org/jruby/truffle/nodes/control/WhenSplatNode.java
  10. +2 −1 truffle/src/main/java/org/jruby/truffle/nodes/core/BindingNodes.java
  11. +15 −14 truffle/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
  12. +9 −8 truffle/src/main/java/org/jruby/truffle/nodes/core/MatchDataNodes.java
  13. +81 −33 truffle/src/main/java/org/jruby/truffle/nodes/core/MethodNodes.java
  14. +21 −20 truffle/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java
  15. +2 −1 truffle/src/main/java/org/jruby/truffle/nodes/core/ObjectSpaceNodes.java
  16. +2 −1 truffle/src/main/java/org/jruby/truffle/nodes/core/ProcNodes.java
  17. +101 −23 truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
  18. +2 −1 truffle/src/main/java/org/jruby/truffle/nodes/core/SymbolNodes.java
  19. +3 −3 truffle/src/main/java/org/jruby/truffle/nodes/core/TrufflePrimitiveNodes.java
  20. +67 −20 truffle/src/main/java/org/jruby/truffle/nodes/core/UnboundMethodNodes.java
  21. +25 −25 truffle/src/main/java/org/jruby/truffle/nodes/core/array/AppendManyNode.java
  22. +18 −18 truffle/src/main/java/org/jruby/truffle/nodes/core/array/AppendOneNode.java
  23. +13 −13 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayBuilderNode.java
  24. +4 −4 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayConcatNode.java
  25. +11 −11 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayDropTailNode.java
  26. +4 −4 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayDupNode.java
  27. +8 −8 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayGetTailNode.java
  28. +26 −26 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayGuards.java
  29. +3 −3 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayLiteralNode.java
  30. +783 −523 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayNodes.java
  31. +2 −2 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayPushNode.java
  32. +1 −1 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayReadDenormalizedNode.java
  33. +5 −5 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayReadNormalizedNode.java
  34. +1 −1 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayReadSliceDenormalizedNode.java
  35. +14 −14 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayReadSliceNormalizedNode.java
  36. +8 −8 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArraySliceNode.java
  37. +1 −1 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayWriteDenormalizedNode.java
  38. +43 −43 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayWriteNormalizedNode.java
  39. +8 −8 truffle/src/main/java/org/jruby/truffle/nodes/core/array/EnsureCapacityArrayNode.java
  40. +7 −7 truffle/src/main/java/org/jruby/truffle/nodes/core/array/GeneralizeArrayNode.java
  41. +6 −6 truffle/src/main/java/org/jruby/truffle/nodes/core/array/PopOneNode.java
  42. +175 −104 truffle/src/main/java/org/jruby/truffle/nodes/core/hash/HashNodes.java
  43. +2 −2 truffle/src/main/java/org/jruby/truffle/nodes/core/hash/LookupEntryNode.java
  44. +3 −2 truffle/src/main/java/org/jruby/truffle/nodes/dispatch/RubyCallNode.java
  45. +2 −1 truffle/src/main/java/org/jruby/truffle/nodes/exceptions/RescueSplatNode.java
  46. +21 −23 truffle/src/main/java/org/jruby/truffle/nodes/interop/InteropNode.java
  47. +6 −5 truffle/src/main/java/org/jruby/truffle/nodes/methods/ExceptionTranslatingNode.java
  48. +2 −1 truffle/src/main/java/org/jruby/truffle/nodes/rubinius/ByteArrayNodes.java
  49. +6 −7 truffle/src/main/java/org/jruby/truffle/nodes/rubinius/IOPrimitiveNodes.java
  50. +4 −3 truffle/src/main/java/org/jruby/truffle/nodes/rubinius/StringPrimitiveNodes.java
  51. +4 −3 truffle/src/main/java/org/jruby/truffle/nodes/rubinius/VMPrimitiveNodes.java
  52. +2 −1 truffle/src/main/java/org/jruby/truffle/nodes/supercall/GeneralSuperCallNode.java
  53. +2 −2 truffle/src/main/java/org/jruby/truffle/nodes/supercall/GeneralSuperReCallNode.java
  54. +2 −1 truffle/src/main/java/org/jruby/truffle/nodes/yield/YieldNode.java
  55. +13 −11 truffle/src/main/java/org/jruby/truffle/runtime/RubyContext.java
  56. +12 −11 truffle/src/main/java/org/jruby/truffle/runtime/core/CoreLibrary.java
  57. +5 −280 truffle/src/main/java/org/jruby/truffle/runtime/core/RubyArray.java
  58. +6 −1 truffle/src/main/java/org/jruby/truffle/runtime/core/RubyBasicObject.java
  59. +2 −1 truffle/src/main/java/org/jruby/truffle/runtime/core/RubyException.java
  60. +7 −76 truffle/src/main/java/org/jruby/truffle/runtime/core/RubyHash.java
  61. +0 −39 truffle/src/main/java/org/jruby/truffle/runtime/core/RubyMethod.java
  62. +0 −1 truffle/src/main/java/org/jruby/truffle/runtime/core/RubyMethodForeignAccessFactory.java
  63. +2 −2 truffle/src/main/java/org/jruby/truffle/runtime/core/RubyRegexp.java
  64. +3 −77 truffle/src/main/java/org/jruby/truffle/runtime/core/RubyString.java
  65. +0 −32 truffle/src/main/java/org/jruby/truffle/runtime/core/RubyUnboundMethod.java
  66. +12 −11 truffle/src/main/java/org/jruby/truffle/runtime/hash/BucketsStrategy.java
  67. +16 −16 truffle/src/main/java/org/jruby/truffle/runtime/hash/HashOperations.java
  68. +2 −2 truffle/src/main/java/org/jruby/truffle/runtime/hash/PackedArrayStrategy.java
  69. +11 −10 truffle/src/main/java/org/jruby/truffle/runtime/subsystems/FeatureManager.java
2 changes: 1 addition & 1 deletion test/mri_truffle.index
Original file line number Diff line number Diff line change
@@ -206,7 +206,7 @@ logger/test_logger.rb
matrix/test_matrix.rb
matrix/test_vector.rb

# monitor/test_monitor.rb # Undefined methods start and join
monitor/test_monitor.rb

# net/ftp/test_ftp.rb
# net/http/test_buffered_io.rb
6 changes: 3 additions & 3 deletions test/pom.rb
Original file line number Diff line number Diff line change
@@ -37,17 +37,17 @@ def truffle_spec_config(spec_type, generate_report)
inherit 'org.jruby:jruby-parent', version
id 'org.jruby:jruby-tests'

repository( 'http://rubygems-proxy.torquebox.org/releases',
repository( :url => 'http://rubygems-proxy.torquebox.org/releases',
:id => 'tb-rubygems-releases' )
repository( :url => 'https://otto.takari.io/content/repositories/rubygems/maven/releases',
:id => 'rubygems-releases' )

plugin_repository( 'https://oss.sonatype.org/content/repositories/snapshots/',
plugin_repository( :url => 'https://oss.sonatype.org/content/repositories/snapshots/',
:id => 'sonatype' ) do
releases 'false'
snapshots 'true'
end
plugin_repository( 'http://rubygems-proxy.torquebox.org/releases',
plugin_repository( :url => 'http://rubygems-proxy.torquebox.org/releases',
:id => 'rubygems-releases' )

properties( 'tesla.dump.pom' => 'pom.xml',
1,092 changes: 0 additions & 1,092 deletions test/pom.xml

This file was deleted.

14 changes: 12 additions & 2 deletions truffle/src/main/java/org/jruby/truffle/nodes/RubyGuards.java
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@

import com.oracle.truffle.api.interop.TruffleObject;
import org.jruby.truffle.nodes.core.BigDecimalNodes;
import org.jruby.truffle.nodes.core.MethodNodes;
import org.jruby.truffle.nodes.core.UnboundMethodNodes;
import org.jruby.truffle.runtime.ThreadLocalObject;
import org.jruby.truffle.runtime.UndefinedPlaceholder;
import org.jruby.truffle.runtime.core.*;
@@ -86,11 +88,19 @@ public static boolean isRubySymbol(Object value) {
}

public static boolean isRubyMethod(Object value) {
return value instanceof RubyMethod;
return (value instanceof RubyBasicObject) && isRubyMethod((RubyBasicObject) value);
}

public static boolean isRubyMethod(RubyBasicObject value) {
return value.getDynamicObject().getShape().getObjectType() == MethodNodes.METHOD_TYPE;
}

public static boolean isRubyUnboundMethod(Object value) {
return value instanceof RubyUnboundMethod;
return (value instanceof RubyBasicObject) && isRubyUnboundMethod((RubyBasicObject) value);
}

public static boolean isRubyUnboundMethod(RubyBasicObject value) {
return value.getDynamicObject().getShape().getObjectType() == UnboundMethodNodes.UNBOUND_METHOD_TYPE;
}

public static boolean isRubyBasicObject(Object value) {
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.hash.HashLiteralNode;
import org.jruby.truffle.nodes.core.hash.HashNodes;
import org.jruby.truffle.nodes.methods.MarkerNode;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
@@ -76,7 +77,7 @@ private Object lookupRestKeywordArgumentHash(VirtualFrame frame) {
entries.add(new KeyValue(keyValue.getKey(), keyValue.getValue()));
}

return HashOperations.verySlowFromEntries(getContext(), entries, hash.isCompareByIdentity());
return HashOperations.verySlowFromEntries(getContext(), entries, HashNodes.isCompareByIdentity(hash));
}

}
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
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;
@@ -24,7 +25,6 @@
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyBignum;

/*
* TODO(CS): could probably unify this with SplatCastNode with some final configuration options.
@@ -85,7 +85,7 @@ public Object cast(Object nil) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass());

case ARRAY_WITH_NIL:
return RubyArray.fromObject(getContext().getCoreLibrary().getArrayClass(), nil());
return ArrayNodes.fromObject(getContext().getCoreLibrary().getArrayClass(), nil());

case NIL:
return nil;
Original file line number Diff line number Diff line change
@@ -9,14 +9,14 @@
*/
package org.jruby.truffle.nodes.cast;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;

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.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBasicObject;
@@ -43,7 +43,7 @@ protected Object castSingle(Object[] args) {
@TruffleBoundary
@Specialization(guards = { "!noArguments(args)", "!singleArgument(args)" })
protected RubyArray castMany(Object[] args) {
return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(), args);
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), args);
}

protected boolean noArguments(Object[] args) {
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.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;
@@ -66,7 +67,7 @@ public RubyArray splat(Object nil) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass());

case ARRAY_WITH_NIL:
return RubyArray.fromObject(getContext().getCoreLibrary().getArrayClass(), nil());
return ArrayNodes.fromObject(getContext().getCoreLibrary().getArrayClass(), nil());

default: {
CompilerAsserts.neverPartOfCompilation();
@@ -101,15 +102,15 @@ public RubyArray splat(VirtualFrame frame, Object object) {
return (RubyArray) array;
} else if (array == nil() || array == DispatchNode.MISSING) {
CompilerDirectives.transferToInterpreter();
return RubyArray.fromObject(getContext().getCoreLibrary().getArrayClass(), object);
return ArrayNodes.fromObject(getContext().getCoreLibrary().getArrayClass(), object);
} else {
throw new RaiseException(getContext().getCoreLibrary().typeErrorCantConvertTo(
object, getContext().getCoreLibrary().getArrayClass(), method, array, this)
);
}
}

return RubyArray.fromObject(getContext().getCoreLibrary().getArrayClass(), object);
return ArrayNodes.fromObject(getContext().getCoreLibrary().getArrayClass(), object);
}

}
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.source.SourceSection;
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.runtime.RubyContext;
@@ -46,7 +47,7 @@ public boolean executeBoolean(VirtualFrame frame) {
throw new UnsupportedOperationException(e);
}

for (Object value : array.slowToArray()) {
for (Object value : ArrayNodes.slowToArray(array)) {
if (dispatchCaseEqual.callBoolean(frame, caseExpression, "===", null, value)) {
return true;
}
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.nodes.locals.ReadFrameSlotNode;
import org.jruby.truffle.nodes.locals.ReadFrameSlotNodeGen;
import org.jruby.truffle.nodes.locals.WriteFrameSlotNode;
@@ -249,7 +250,7 @@ public RubyArray localVariables(RubyBinding binding) {
while (frame != null) {
for (Object name : frame.getFrameDescriptor().getIdentifiers()) {
if (name instanceof String) {
array.slowPush(getContext().getSymbol((String) name));
ArrayNodes.slowPush(array, getContext().getSymbol((String) name));
}
}

29 changes: 15 additions & 14 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@
import org.jruby.truffle.nodes.core.KernelNodesFactory.CopyNodeFactory;
import org.jruby.truffle.nodes.core.KernelNodesFactory.SameOrEqualNodeFactory;
import org.jruby.truffle.nodes.core.KernelNodesFactory.SingletonMethodsNodeFactory;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.nodes.dispatch.*;
import org.jruby.truffle.nodes.objects.*;
import org.jruby.truffle.nodes.objectstorage.WriteHeadObjectFieldNode;
@@ -910,7 +911,7 @@ public RubyArray instanceVariables(RubyBasicObject self) {

for (Object name : instanceVariableNames) {
if (name instanceof String) {
array.slowPush(getContext().getSymbolTable().getSymbol((String) name));
ArrayNodes.slowPush(array, getContext().getSymbolTable().getSymbol((String) name));
}
}

@@ -1010,7 +1011,7 @@ public RubyArray localVariables() {

for (Object name : Truffle.getRuntime().getCallerFrame().getFrame(FrameInstance.FrameAccess.READ_ONLY, false).getFrameDescriptor().getIdentifiers()) {
if (name instanceof String) {
array.slowPush(getContext().getSymbol((String) name));
ArrayNodes.slowPush(array, getContext().getSymbol((String) name));
}
}

@@ -1043,16 +1044,16 @@ public MethodNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public RubyMethod method(Object object, RubySymbol name) {
public RubyBasicObject method(Object object, RubySymbol name) {
return method(object, name.toString());
}

@Specialization
public RubyMethod method(Object object, RubyString name) {
public RubyBasicObject method(Object object, RubyString name) {
return method(object, name.toString());
}

private RubyMethod method(Object object, String name) {
private RubyBasicObject method(Object object, String name) {
CompilerDirectives.transferToInterpreter();

// TODO(CS, 11-Jan-15) cache this lookup
@@ -1065,7 +1066,7 @@ private RubyMethod method(Object object, String name) {
name, getContext().getCoreLibrary().getLogicalClass(object), this));
}

return new RubyMethod(getContext().getCoreLibrary().getMethodClass(), object, method);
return MethodNodes.createMethod(getContext().getCoreLibrary().getMethodClass(), object, method);
}

}
@@ -1093,7 +1094,7 @@ public RubyArray methods(VirtualFrame frame, Object self, boolean regular) {

CompilerDirectives.transferToInterpreter();
if (regular) {
return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(),
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(),
metaClass.filterMethodsOnObject(regular, MethodFilter.PUBLIC_PROTECTED).toArray());
} else {
if (singletonMethodsNode == null) {
@@ -1149,7 +1150,7 @@ public RubyArray privateMethods(VirtualFrame frame, Object self, boolean include
RubyClass metaClass = metaClassNode.executeMetaClass(frame, self);

CompilerDirectives.transferToInterpreter();
return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(),
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(),
metaClass.filterMethodsOnObject(includeAncestors, MethodFilter.PRIVATE).toArray());
}

@@ -1203,7 +1204,7 @@ public RubyArray protectedMethods(VirtualFrame frame, Object self, boolean inclu
RubyClass metaClass = metaClassNode.executeMetaClass(frame, self);

CompilerDirectives.transferToInterpreter();
return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(),
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(),
metaClass.filterMethodsOnObject(includeAncestors, MethodFilter.PROTECTED).toArray());
}

@@ -1239,7 +1240,7 @@ public RubyArray publicMethods(VirtualFrame frame, Object self, boolean includeA
RubyClass metaClass = metaClassNode.executeMetaClass(frame, self);

CompilerDirectives.transferToInterpreter();
return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(),
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(),
metaClass.filterMethodsOnObject(includeAncestors, MethodFilter.PUBLIC).toArray());
}

@@ -1543,7 +1544,7 @@ public RubyArray singletonMethods(VirtualFrame frame, Object self, boolean inclu
}

CompilerDirectives.transferToInterpreter();
return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(),
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(),
metaClass.filterSingletonMethods(includeAncestors, MethodFilter.PUBLIC_PROTECTED).toArray());
}

@@ -1733,17 +1734,17 @@ private RubyString finishFormat(ByteList format, PackResult result) {
final RubyString string = getContext().makeString(new ByteList(result.getOutput(), 0, result.getOutputLength()));

if (format.length() == 0) {
string.forceEncoding(USASCIIEncoding.INSTANCE);
StringNodes.forceEncoding(string, USASCIIEncoding.INSTANCE);
} else {
switch (result.getEncoding()) {
case DEFAULT:
case ASCII_8BIT:
break;
case US_ASCII:
string.forceEncoding(USASCIIEncoding.INSTANCE);
StringNodes.forceEncoding(string, USASCIIEncoding.INSTANCE);
break;
case UTF_8:
string.forceEncoding(UTF8Encoding.INSTANCE);
StringNodes.forceEncoding(string, UTF8Encoding.INSTANCE);
break;
default:
throw new UnsupportedOperationException();
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.coerce.ToIntNode;
import org.jruby.truffle.nodes.coerce.ToIntNodeGen;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.UndefinedPlaceholder;
import org.jruby.truffle.runtime.control.RaiseException;
@@ -44,7 +45,7 @@ public Object getIndex(RubyMatchData matchData, int index, UndefinedPlaceholder
CompilerDirectives.transferToInterpreter();

final Object[] values = matchData.getValues();
final int normalizedIndex = RubyArray.normalizeIndex(values.length, index);
final int normalizedIndex = ArrayNodes.normalizeIndex(values.length, index);

if ((normalizedIndex < 0) || (normalizedIndex >= values.length)) {
return nil();
@@ -58,7 +59,7 @@ public Object getIndex(RubyMatchData matchData, int index, int length) {
CompilerDirectives.transferToInterpreter();
// TODO BJF 15-May-2015 Need to handle negative indexes and lengths and out of bounds
final Object[] values = matchData.getValues();
final int normalizedIndex = RubyArray.normalizeIndex(values.length, index);
final int normalizedIndex = ArrayNodes.normalizeIndex(values.length, index);
final Object[] store = Arrays.copyOfRange(values, normalizedIndex, normalizedIndex + length);
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), store, length);
}
@@ -111,9 +112,9 @@ public Object getIndex(VirtualFrame frame, RubyMatchData matchData, Object index
@Specialization(guards = {"!isRubySymbol(range)", "!isRubyString(range)"})
public Object getIndex(VirtualFrame frame, RubyMatchData matchData, RubyRange.IntegerFixnumRange range, UndefinedPlaceholder undefinedPlaceholder) {
final Object[] values = matchData.getValues();
final int normalizedIndex = RubyArray.normalizeIndex(values.length, range.getBegin());
final int end = RubyArray.normalizeIndex(values.length, range.getEnd());
final int exclusiveEnd = RubyArray.clampExclusiveIndex(values.length, range.doesExcludeEnd() ? end : end + 1);
final int normalizedIndex = ArrayNodes.normalizeIndex(values.length, range.getBegin());
final int end = ArrayNodes.normalizeIndex(values.length, range.getEnd());
final int exclusiveEnd = ArrayNodes.clampExclusiveIndex(values.length, range.doesExcludeEnd() ? end : end + 1);
final int length = exclusiveEnd - normalizedIndex;

final Object[] store = Arrays.copyOfRange(values, normalizedIndex, normalizedIndex + length);
@@ -159,7 +160,7 @@ public CapturesNode(RubyContext context, SourceSection sourceSection) {
public RubyArray toA(RubyMatchData matchData) {
CompilerDirectives.transferToInterpreter();

return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(), matchData.getCaptures());
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), matchData.getCaptures());
}
}

@@ -241,7 +242,7 @@ public ToANode(RubyContext context, SourceSection sourceSection) {
public RubyArray toA(RubyMatchData matchData) {
CompilerDirectives.transferToInterpreter();

return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(), matchData.getValues());
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), matchData.getValues());
}
}

@@ -278,7 +279,7 @@ public RubyArray valuesAt(RubyMatchData matchData, Object[] args) {
indicies[n] = (int) args[n];
}

return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(), matchData.valuesAt(indicies));
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), matchData.valuesAt(indicies));
}

}
114 changes: 81 additions & 33 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/MethodNodes.java
Original file line number Diff line number Diff line change
@@ -15,24 +15,70 @@
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.IndirectCallNode;
import com.oracle.truffle.api.object.*;
import com.oracle.truffle.api.source.NullSourceSection;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.ast.ArgsNode;
import org.jruby.runtime.ArgumentDescriptor;
import org.jruby.runtime.Helpers;
import org.jruby.truffle.nodes.core.BasicObjectNodes.ReferenceEqualNode;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.nodes.objects.ClassNode;
import org.jruby.truffle.nodes.objects.ClassNodeGen;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.UndefinedPlaceholder;
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.methods.InternalMethod;
import org.jruby.truffle.runtime.object.BasicObjectType;

import java.util.EnumSet;

@CoreClass(name = "Method")
public abstract class MethodNodes {

public static class MethodType extends BasicObjectType {

}

public static final MethodType METHOD_TYPE = new MethodType();

private static final HiddenKey RECEIVER_IDENTIFIER = new HiddenKey("receiver");
public static final Property RECEIVER_PROPERTY;

private static final HiddenKey METHOD_IDENTIFIER = new HiddenKey("method");
public static final Property METHOD_PROPERTY;

private static final DynamicObjectFactory METHOD_FACTORY;

static {
final Shape.Allocator allocator = RubyBasicObject.LAYOUT.createAllocator();

RECEIVER_PROPERTY = Property.create(RECEIVER_IDENTIFIER, allocator.locationForType(Object.class, EnumSet.of(LocationModifier.Final, LocationModifier.NonNull)), 0);
METHOD_PROPERTY = Property.create(METHOD_IDENTIFIER, allocator.locationForType(InternalMethod.class, EnumSet.of(LocationModifier.Final, LocationModifier.NonNull)), 0);

final Shape shape = RubyBasicObject.LAYOUT.createShape(METHOD_TYPE)
.addProperty(RECEIVER_PROPERTY)
.addProperty(METHOD_PROPERTY);

METHOD_FACTORY = shape.createFactory();
}

public static RubyBasicObject createMethod(RubyClass rubyClass, Object receiver, InternalMethod method) {
return new RubyBasicObject(rubyClass, METHOD_FACTORY.newInstance(receiver, method));
}

public static Object getReceiver(RubyBasicObject method) {
assert method.getDynamicObject().getShape().hasProperty(RECEIVER_IDENTIFIER);
return RECEIVER_PROPERTY.get(method.getDynamicObject(), true);
}

public static InternalMethod getMethod(RubyBasicObject method) {
assert method.getDynamicObject().getShape().hasProperty(METHOD_IDENTIFIER);
return (InternalMethod) METHOD_PROPERTY.get(method.getDynamicObject(), true);
}

@CoreMethod(names = { "==", "eql?" }, required = 1)
public abstract static class EqualNode extends CoreMethodArrayArgumentsNode {

@@ -50,13 +96,13 @@ protected boolean areSame(VirtualFrame frame, Object left, Object right) {
return referenceEqualNode.executeReferenceEqual(frame, left, right);
}

@Specialization
public boolean equal(VirtualFrame frame, RubyMethod a, RubyMethod b) {
return areSame(frame, a.getReceiver(), b.getReceiver()) && a.getMethod() == b.getMethod();
@Specialization(guards = "isRubyMethod(b)")
public boolean equal(VirtualFrame frame, RubyBasicObject a, RubyBasicObject b) {
return areSame(frame, getReceiver(a), getReceiver(b)) && getMethod(a) == getMethod(b);
}

@Specialization(guards = "!isRubyMethod(b)")
public boolean equal(RubyMethod a, Object b) {
public boolean equal(RubyBasicObject a, Object b) {
return false;
}

@@ -70,8 +116,8 @@ public ArityNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public int arity(RubyMethod method) {
return method.getMethod().getSharedMethodInfo().getArity().getArityNumber();
public int arity(RubyBasicObject method) {
return getMethod(method).getSharedMethodInfo().getArity().getArityNumber();
}

}
@@ -87,21 +133,21 @@ public CallNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public Object call(VirtualFrame frame, RubyMethod method, Object[] arguments, UndefinedPlaceholder block) {
public Object call(VirtualFrame frame, RubyBasicObject method, Object[] arguments, UndefinedPlaceholder block) {
return doCall(frame, method, arguments, null);
}

@Specialization
public Object doCall(VirtualFrame frame, RubyMethod method, Object[] arguments, RubyProc block) {
public Object doCall(VirtualFrame frame, RubyBasicObject method, Object[] arguments, RubyProc block) {
// TODO(CS 11-Jan-15) should use a cache and DirectCallNode here so that we can inline - but it's
// incompatible with our current dispatch chain.

final InternalMethod internalMethod = method.getMethod();
final InternalMethod internalMethod = getMethod(method);

return callNode.call(frame, method.getMethod().getCallTarget(), RubyArguments.pack(
return callNode.call(frame, getMethod(method).getCallTarget(), RubyArguments.pack(
internalMethod,
internalMethod.getDeclarationFrame(),
method.getReceiver(),
getReceiver(method),
block,
arguments));
}
@@ -116,10 +162,10 @@ public NameNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public RubySymbol name(RubyMethod method) {
public RubySymbol name(RubyBasicObject method) {
CompilerDirectives.transferToInterpreter();

return getContext().getSymbol(method.getMethod().getName());
return getContext().getSymbol(getMethod(method).getName());
}

}
@@ -132,8 +178,8 @@ public OwnerNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public RubyModule owner(RubyMethod method) {
return method.getMethod().getDeclaringModule();
public RubyModule owner(RubyBasicObject method) {
return getMethod(method).getDeclaringModule();
}

}
@@ -147,8 +193,8 @@ public ParametersNode(RubyContext context, SourceSection sourceSection) {

@TruffleBoundary
@Specialization
public RubyArray parameters(RubyMethod method) {
final ArgsNode argsNode = method.getMethod().getSharedMethodInfo().getParseTree().findFirstChild(ArgsNode.class);
public RubyArray parameters(RubyBasicObject method) {
final ArgsNode argsNode = getMethod(method).getSharedMethodInfo().getParseTree().findFirstChild(ArgsNode.class);

final ArgumentDescriptor[] argsDesc = Helpers.argsNodeToArgumentDescriptors(argsNode);

@@ -166,8 +212,8 @@ public ReceiverNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public Object receiver(RubyMethod method) {
return method.getReceiver();
public Object receiver(RubyBasicObject method) {
return getReceiver(method);
}

}
@@ -180,16 +226,16 @@ public SourceLocationNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public Object sourceLocation(RubyMethod method) {
public Object sourceLocation(RubyBasicObject method) {
CompilerDirectives.transferToInterpreter();

SourceSection sourceSection = method.getMethod().getSharedMethodInfo().getSourceSection();
SourceSection sourceSection = getMethod(method).getSharedMethodInfo().getSourceSection();

if (sourceSection instanceof NullSourceSection) {
return nil();
} else {
RubyString file = getContext().makeString(sourceSection.getSource().getName());
return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(),
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(),
file, sourceSection.getStartLine());
}
}
@@ -207,11 +253,11 @@ public UnbindNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public RubyUnboundMethod unbind(VirtualFrame frame, RubyMethod method) {
public RubyBasicObject unbind(VirtualFrame frame, RubyBasicObject method) {
CompilerDirectives.transferToInterpreter();

RubyClass receiverClass = classNode.executeGetClass(frame, method.getReceiver());
return new RubyUnboundMethod(getContext().getCoreLibrary().getUnboundMethodClass(), receiverClass, method.getMethod());
RubyClass receiverClass = classNode.executeGetClass(frame, getReceiver(method));
return UnboundMethodNodes.createUnboundMethod(getContext().getCoreLibrary().getUnboundMethodClass(), receiverClass, getMethod(method));
}

}
@@ -224,17 +270,19 @@ public ToProcNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public RubyProc toProc(RubyMethod method) {
public RubyProc toProc(RubyBasicObject methodObject) {
final InternalMethod method = getMethod(methodObject);

return new RubyProc(
getContext().getCoreLibrary().getProcClass(),
RubyProc.Type.LAMBDA,
method.getMethod().getSharedMethodInfo(),
method.getMethod().getCallTarget(),
method.getMethod().getCallTarget(),
method.getMethod().getCallTarget(),
method.getMethod().getDeclarationFrame(),
method.getMethod(),
method.getReceiver(),
method.getSharedMethodInfo(),
method.getCallTarget(),
method.getCallTarget(),
method.getCallTarget(),
method.getDeclarationFrame(),
method,
getReceiver(methodObject),
null);
}

41 changes: 21 additions & 20 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@
import org.jruby.truffle.nodes.core.KernelNodes.BindingNode;
import org.jruby.truffle.nodes.core.ModuleNodesFactory.SetMethodVisibilityNodeGen;
import org.jruby.truffle.nodes.core.ModuleNodesFactory.SetVisibilityNodeGen;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.nodes.methods.SetMethodDeclarationContext;
import org.jruby.truffle.nodes.objects.*;
import org.jruby.truffle.nodes.yield.YieldDispatchHeadNode;
@@ -335,7 +336,7 @@ public RubyArray ancestors(RubyModule self) {
ancestors.add(module);
}

return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(), ancestors.toArray(new Object[ancestors.size()]));
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), ancestors.toArray(new Object[ancestors.size()]));
}
}

@@ -750,7 +751,7 @@ public RubyArray getClassVariables(RubyModule module) {
final RubyArray array = new RubyArray(module.getContext().getCoreLibrary().getArrayClass());

for (String variable : ModuleOperations.getAllClassVariables(module).keySet()) {
array.slowPush(RubySymbol.newSymbol(module.getContext(), variable));
ArrayNodes.slowPush(array, RubySymbol.newSymbol(module.getContext(), variable));
}
return array;
}
@@ -797,7 +798,7 @@ public RubyArray constants(RubyModule module, boolean inherit) {
}
}

return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(), constantsArray.toArray(new Object[constantsArray.size()]));
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), constantsArray.toArray(new Object[constantsArray.size()]));
}

@Specialization(guards = "!isUndefinedPlaceholder(inherit)")
@@ -1014,25 +1015,25 @@ public RubySymbol defineMethod(RubyModule module, String name, RubyProc proc, Un
}

@TruffleBoundary
@Specialization
public RubySymbol defineMethod(RubyModule module, String name, RubyMethod method, UndefinedPlaceholder block) {
module.addMethod(this, method.getMethod().withName(name));
@Specialization(guards = "isRubyMethod(method)")
public RubySymbol defineMethod(RubyModule module, String name, RubyBasicObject method, UndefinedPlaceholder block) {
module.addMethod(this, MethodNodes.getMethod(method).withName(name));
return getContext().getSymbolTable().getSymbol(name);
}

@Specialization
public RubySymbol defineMethod(VirtualFrame frame, RubyModule module, String name, RubyUnboundMethod method, UndefinedPlaceholder block) {
@Specialization(guards = "isRubyUnboundMethod(method)")
public RubySymbol defineMethod(VirtualFrame frame, RubyModule module, String name, RubyBasicObject method, UndefinedPlaceholder block) {
CompilerDirectives.transferToInterpreter();

RubyModule origin = method.getOrigin();
RubyModule origin = UnboundMethodNodes.getOrigin(method);
if (!ModuleOperations.canBindMethodTo(origin, module)) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeError("bind argument must be a subclass of " + origin.getName(), this));
}

// TODO CS 5-Apr-15 TypeError if the method came from a singleton

return addMethod(module, name, method.getMethod());
return addMethod(module, name, UnboundMethodNodes.getMethod(method));
}

private RubySymbol defineMethod(RubyModule module, String name, RubyProc proc) {
@@ -1179,7 +1180,7 @@ RubyArray includedModules(RubyModule module) {
}
}

return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(), modules.toArray(new Object[modules.size()]));
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), modules.toArray(new Object[modules.size()]));
}
}

@@ -1286,7 +1287,7 @@ public RubyArray nesting(VirtualFrame frame) {
lexicalScope = lexicalScope.getParent();
}

return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(), modules.toArray(new Object[modules.size()]));
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), modules.toArray(new Object[modules.size()]));
}
}

@@ -1419,7 +1420,7 @@ public RubyArray protectedInstanceMethods(RubyModule module, boolean includeAnce
CompilerDirectives.transferToInterpreter();


return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(),
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(),
module.filterMethods(includeAncestors, MethodFilter.PROTECTED).toArray());
}
}
@@ -1466,7 +1467,7 @@ public RubyArray privateInstanceMethods(RubyModule module, UndefinedPlaceholder
public RubyArray privateInstanceMethods(RubyModule module, boolean includeAncestors) {
CompilerDirectives.transferToInterpreter();

return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(),
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(),
module.filterMethods(includeAncestors, MethodFilter.PRIVATE).toArray());
}
}
@@ -1488,7 +1489,7 @@ public RubyNode coerceToString(RubyNode name) {
}

@Specialization
public RubyUnboundMethod publicInstanceMethod(RubyModule module, String name) {
public RubyBasicObject publicInstanceMethod(RubyModule module, String name) {
CompilerDirectives.transferToInterpreter();

// TODO(CS, 11-Jan-15) cache this lookup
@@ -1502,7 +1503,7 @@ public RubyUnboundMethod publicInstanceMethod(RubyModule module, String name) {
throw new RaiseException(getContext().getCoreLibrary().nameErrorPrivateMethod(name, module, this));
}

return new RubyUnboundMethod(getContext().getCoreLibrary().getUnboundMethodClass(), module, method);
return UnboundMethodNodes.createUnboundMethod(getContext().getCoreLibrary().getUnboundMethodClass(), module, method);
}

}
@@ -1523,7 +1524,7 @@ public RubyArray publicInstanceMethods(RubyModule module, UndefinedPlaceholder a
public RubyArray publicInstanceMethods(RubyModule module, boolean includeAncestors) {
CompilerDirectives.transferToInterpreter();

return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(),
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(),
module.filterMethods(includeAncestors, MethodFilter.PUBLIC).toArray());
}
}
@@ -1570,7 +1571,7 @@ public RubyArray instanceMethods(RubyModule module, UndefinedPlaceholder argumen
public RubyArray instanceMethods(RubyModule module, boolean includeAncestors) {
CompilerDirectives.transferToInterpreter();

return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(),
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(),
module.filterMethods(includeAncestors, MethodFilter.PUBLIC_PROTECTED).toArray());
}
}
@@ -1592,7 +1593,7 @@ public RubyNode coerceToString(RubyNode name) {
}

@Specialization
public RubyUnboundMethod instanceMethod(RubyModule module, String name) {
public RubyBasicObject instanceMethod(RubyModule module, String name) {
CompilerDirectives.transferToInterpreter();

// TODO(CS, 11-Jan-15) cache this lookup
@@ -1603,7 +1604,7 @@ public RubyUnboundMethod instanceMethod(RubyModule module, String name) {
throw new RaiseException(getContext().getCoreLibrary().nameErrorUndefinedMethod(name, module, this));
}

return new RubyUnboundMethod(getContext().getCoreLibrary().getUnboundMethodClass(), module, method);
return UnboundMethodNodes.createUnboundMethod(getContext().getCoreLibrary().getUnboundMethodClass(), module, method);
}

}
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.runtime.ModuleOperations;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.UndefinedPlaceholder;
@@ -134,7 +135,7 @@ public DefineFinalizerNode(RubyContext context, SourceSection sourceSection) {
@Specialization
public RubyArray defineFinalizer(Object object, RubyProc finalizer) {
getContext().getObjectSpaceManager().defineFinalizer((RubyBasicObject) object, finalizer);
return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(), 0, finalizer);
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), 0, finalizer);
}
}

Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@
import org.jruby.ast.ArgsNode;
import org.jruby.runtime.ArgumentDescriptor;
import org.jruby.runtime.Helpers;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.nodes.yield.YieldDispatchHeadNode;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
@@ -189,7 +190,7 @@ public Object sourceLocation(RubyProc proc) {
return nil();
} else {
RubyString file = getContext().makeString(sourceSection.getSource().getName());
return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(),
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(),
file, sourceSection.getStartLine());
}
}
124 changes: 101 additions & 23 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.*;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.BranchProfile;
import com.oracle.truffle.api.utilities.ConditionProfile;
@@ -48,9 +49,11 @@
import org.jruby.truffle.nodes.coerce.ToStrNode;
import org.jruby.truffle.nodes.coerce.ToStrNodeGen;
import org.jruby.truffle.nodes.core.array.ArrayCoreMethodNode;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.nodes.core.fixnum.FixnumLowerNode;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.nodes.objects.Allocator;
import org.jruby.truffle.nodes.objects.IsFrozenNode;
import org.jruby.truffle.nodes.objects.IsFrozenNodeGen;
import org.jruby.truffle.nodes.rubinius.StringPrimitiveNodes;
@@ -69,6 +72,73 @@
@CoreClass(name = "String")
public abstract class StringNodes {

public static RubyString fromJavaString(RubyClass stringClass, String string) {
return new RubyString(stringClass, new ByteList(org.jruby.RubyEncoding.encodeUTF8(string), USASCIIEncoding.INSTANCE, false));
}

public static RubyString fromJavaString(RubyClass stringClass, String string, Encoding encoding) {
return new RubyString(stringClass, new ByteList(org.jruby.RubyEncoding.encodeUTF8(string), encoding, false));
}

public static RubyString fromByteList(RubyClass stringClass, ByteList bytes) {
return new RubyString(stringClass, bytes);
}

public static void set(RubyString string, ByteList bytes) {
string.bytes = bytes;
}

public static void forceEncoding(RubyString string, Encoding encoding) {
string.modify();
string.clearCodeRange();
StringSupport.associateEncoding(string, encoding);
string.clearCodeRange();
}

public static int length(RubyString string) {
if (CompilerDirectives.injectBranchProbability(
CompilerDirectives.FASTPATH_PROBABILITY,
StringSupport.isSingleByteOptimizable(string, string.getByteList().getEncoding()))) {

return string.getByteList().getRealSize();

} else {
return StringSupport.strLengthFromRubyString(string);
}
}

public static int normalizeIndex(int length, int index) {
return ArrayNodes.normalizeIndex(length, index);
}

public static int normalizeIndex(RubyString rubyString, int index) {
return normalizeIndex(length(rubyString), index);
}

public static int clampExclusiveIndex(RubyString string, int index) {
return ArrayNodes.clampExclusiveIndex(string.bytes.length(), index);
}

@TruffleBoundary
public static Encoding checkEncoding(RubyString string, CodeRangeable other, Node node) {
final Encoding encoding = StringSupport.areCompatible(string, other);

if (encoding == null) {
throw new RaiseException(
string.getContext().getCoreLibrary().encodingCompatibilityErrorIncompatible(
string.getByteList().getEncoding().toString(),
other.getByteList().getEncoding().toString(),
node)
);
}

return encoding;
}

public static boolean singleByteOptimizable(RubyString string) {
return StringSupport.isSingleByteOptimizable(string, EncodingUtils.STR_ENC_GET(string));
}

@CoreMethod(names = "+", required = 1)
@NodeChildren({
@NodeChild(type = RubyNode.class, value = "string"),
@@ -88,7 +158,7 @@ public AddNode(RubyContext context, SourceSection sourceSection) {

@Specialization
public RubyString add(RubyString string, RubyString other) {
final Encoding enc = string.checkEncoding(other, this);
final Encoding enc = checkEncoding(string, other, this);
final RubyString ret = getContext().makeString(getContext().getCoreLibrary().getStringClass(),
StringSupport.addByteLists(string.getByteList(), other.getByteList()));

@@ -405,7 +475,7 @@ public GetIndexNode(RubyContext context, SourceSection sourceSection) {

@Specialization
public Object getIndex(VirtualFrame frame, RubyString string, int index, UndefinedPlaceholder undefined) {
int normalizedIndex = string.normalizeIndex(index);
int normalizedIndex = normalizeIndex(string, index);
final ByteList bytes = string.getByteList();

if (normalizedIndex < 0 || normalizedIndex >= bytes.length()) {
@@ -448,7 +518,7 @@ private Object sliceRange(VirtualFrame frame, RubyString string, int begin, int
}

final int stringLength = sizeNode.executeInteger(frame, string);
begin = string.normalizeIndex(stringLength, begin);
begin = normalizeIndex(stringLength, begin);

if (begin < 0 || begin > stringLength) {
outOfBounds.enter();
@@ -459,8 +529,8 @@ private Object sliceRange(VirtualFrame frame, RubyString string, int begin, int
return getContext().makeString(string.getLogicalClass(), "", string.getByteList().getEncoding());
}

end = string.normalizeIndex(stringLength, end);
int length = string.clampExclusiveIndex(doesExcludeEnd ? end : end + 1);
end = normalizeIndex(stringLength, end);
int length = clampExclusiveIndex(string, doesExcludeEnd ? end : end + 1);

if (length > stringLength) {
length = stringLength;
@@ -758,7 +828,7 @@ private int countSlow(RubyString string, RubyString[] otherStrings) {
for (int i = 1; i < otherStrings.length; i++) {
otherStr = otherStrings[i];

enc = string.checkEncoding(otherStr, this);
enc = checkEncoding(string, otherStr, this);
tables = StringSupport.trSetupTable(otherStr.getByteList(), getContext().getRuntime(), table, tables, false, enc);
}

@@ -872,15 +942,15 @@ public Object deleteBang(VirtualFrame frame, RubyString string, Object... args)
@TruffleBoundary
private Object deleteBangSlow(RubyString string, RubyString... otherStrings) {
RubyString otherString = otherStrings[0];
Encoding enc = string.checkEncoding(otherString, this);
Encoding enc = checkEncoding(string, otherString, this);

boolean[] squeeze = new boolean[StringSupport.TRANS_SIZE + 1];
StringSupport.TrTables tables = StringSupport.trSetupTable(otherString.getByteList(),
getContext().getRuntime(),
squeeze, null, true, enc);

for (int i = 1; i < otherStrings.length; i++) {
enc = string.checkEncoding(otherStrings[i], this);
enc = checkEncoding(string, otherStrings[i], this);
tables = StringSupport.trSetupTable(otherStrings[i].getByteList(), getContext().getRuntime(), squeeze, tables, false, enc);
}

@@ -922,7 +992,7 @@ public RubyBasicObject downcase(RubyString string) {
if (newByteList.equal(string.getByteList())) {
return nil();
} else {
string.set(newByteList);
set(string, newByteList);
return string;
}
}
@@ -1074,7 +1144,7 @@ public RubyString forceEncoding(RubyString string, RubyString encodingName) {

@Specialization
public RubyString forceEncoding(RubyString string, RubyEncoding encoding) {
string.forceEncoding(encoding.getEncoding());
StringNodes.forceEncoding(string, encoding.getEncoding());
return string;
}

@@ -1174,7 +1244,7 @@ public RubyString initialize(RubyString self, RubyString from) {
}

// TODO (nirvdrum 03-Apr-15): Rather than dup every time, we should do CoW on String mutations.
self.set(from.getByteList().dup());
set(self, from.getByteList().dup());
self.setCodeRange(from.getCodeRange());

return self;
@@ -1622,7 +1692,7 @@ public RubyString scan(VirtualFrame frame, RubyString string, RubyString regexpS

@Specialization
public RubyArray scan(RubyString string, RubyRegexp regexp, UndefinedPlaceholder block) {
return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(), (Object[]) regexp.scan(string));
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), (Object[]) regexp.scan(string));
}

@Specialization
@@ -1762,7 +1832,7 @@ public Object squeezeBangZeroArgs(VirtualFrame frame, RubyString string, Object.

string.modifyAndKeepCodeRange();

if (singleByteOptimizableProfile.profile(string.singleByteOptimizable())) {
if (singleByteOptimizableProfile.profile(singleByteOptimizable(string))) {
if (! StringSupport.singleByteSqueeze(string.getByteList(), squeeze)) {
return nil();
}
@@ -1795,16 +1865,16 @@ public Object squeezeBang(VirtualFrame frame, RubyString string, Object... args)
}

RubyString otherStr = otherStrings[0];
Encoding enc = string.checkEncoding(otherStr, this);
Encoding enc = checkEncoding(string, otherStr, this);
final boolean squeeze[] = new boolean[StringSupport.TRANS_SIZE + 1];
StringSupport.TrTables tables = StringSupport.trSetupTable(otherStr.getByteList(), getContext().getRuntime(), squeeze, null, true, enc);

boolean singlebyte = string.singleByteOptimizable() && otherStr.singleByteOptimizable();
boolean singlebyte = singleByteOptimizable(string) && singleByteOptimizable(otherStr);

for (int i = 1; i < otherStrings.length; i++) {
otherStr = otherStrings[i];
enc = string.checkEncoding(otherStr);
singlebyte = singlebyte && otherStr.singleByteOptimizable();
singlebyte = singlebyte && singleByteOptimizable(otherStr);
tables = StringSupport.trSetupTable(otherStr.getByteList(), getContext().getRuntime(), squeeze, tables, false, enc);
}

@@ -1843,7 +1913,7 @@ public SuccNode(RubyContext context, SourceSection sourceSection) {
@TruffleBoundary
@Specialization
public RubyString succ(RubyString string) {
if (string.length() > 0) {
if (length(string) > 0) {
return getContext().makeString(string.getLogicalClass(), StringSupport.succCommon(getContext().getRuntime(), string.getByteList()));
} else {
return getContext().makeString(string.getLogicalClass(), "");
@@ -1862,7 +1932,7 @@ public SuccBangNode(RubyContext context, SourceSection sourceSection) {
@Specialization
public RubyString succBang(RubyString string) {
if (string.getByteList().getRealSize() > 0) {
string.set(StringSupport.succCommon(getContext().getRuntime(), string.getByteList()));
set(string, StringSupport.succCommon(getContext().getRuntime(), string.getByteList()));
}

return string;
@@ -2195,7 +2265,7 @@ public RubyBasicObject upcaseBang(RubyString string) {
if (byteListString.equal(string.getByteList())) {
return nil();
} else {
string.set(byteListString);
set(string, byteListString);
return string;
}
}
@@ -2304,7 +2374,7 @@ public ClearNode(RubyContext context, SourceSection sourceSection) {
public RubyString clear(RubyString string) {
ByteList empty = ByteList.EMPTY_BYTELIST;
empty.setEncoding(string.getByteList().getEncoding());
string.set(empty);
set(string, empty);
return string;
}
}
@@ -2322,22 +2392,22 @@ public static ByteList downcase(Ruby runtime, ByteList string) {
}

public static int checkIndex(RubyString string, int index, RubyNode node) {
if (index > string.length()) {
if (index > length(string)) {
CompilerDirectives.transferToInterpreter();

throw new RaiseException(
node.getContext().getCoreLibrary().indexError(String.format("index %d out of string", index), node));
}

if (index < 0) {
if (-index > string.length()) {
if (-index > length(string)) {
CompilerDirectives.transferToInterpreter();

throw new RaiseException(
node.getContext().getCoreLibrary().indexError(String.format("index %d out of string", index), node));
}

index += string.length();
index += length(string);
}

return index;
@@ -2384,4 +2454,12 @@ private static Object trTransHelper(RubyContext context, RubyString self, RubySt
}
}

public static class StringAllocator implements Allocator {

@Override
public RubyBasicObject allocate(RubyContext context, RubyClass rubyClass, Node currentNode) {
return new RubyString(rubyClass, new ByteList());
}

}
}
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.*;
import org.jruby.util.ByteList;
@@ -72,7 +73,7 @@ public RubyArray allSymbols() {
final RubyArray array = new RubyArray(getContext().getCoreLibrary().getArrayClass());

for (RubySymbol s : getContext().getSymbolTable().allSymbols()) {
array.slowPush(s);
ArrayNodes.slowPush(array, s);
}
return array;
}
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
*/
package org.jruby.truffle.nodes.core;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.dsl.Specialization;
@@ -21,6 +20,7 @@

import org.jruby.RubyGC;
import org.jruby.ext.rbconfig.RbConfigLibrary;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.cext.CExtManager;
@@ -375,11 +375,11 @@ public boolean cExtLoad(RubyArray initFunctions, RubyArray cFlags, RubyArray fil
}

private String[] toStrings(RubyArray array) {
final String[] strings = new String[array.getSize()];
final String[] strings = new String[ArrayNodes.getSize(array)];

int n = 0;

for (Object object : array.slowToArray()) {
for (Object object : ArrayNodes.slowToArray(array)) {
if (object instanceof RubyString || object instanceof RubySymbol) {
strings[n] = object.toString();
n++;
Original file line number Diff line number Diff line change
@@ -13,37 +13,84 @@
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.*;
import com.oracle.truffle.api.source.NullSourceSection;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.ast.ArgsNode;
import org.jruby.runtime.ArgumentDescriptor;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.nodes.objects.MetaClassNode;
import org.jruby.truffle.nodes.objects.MetaClassNodeGen;
import org.jruby.truffle.runtime.ModuleOperations;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.methods.InternalMethod;
import org.jruby.truffle.runtime.object.BasicObjectType;

import java.util.EnumSet;

@CoreClass(name = "UnboundMethod")
public abstract class UnboundMethodNodes {

public static class MethodType extends BasicObjectType {

}

public static final MethodType UNBOUND_METHOD_TYPE = new MethodType();

private static final HiddenKey ORIGIN_IDENTIFIER = new HiddenKey("origin");
public static final Property ORIGIN_PROPERTY;

private static final HiddenKey METHOD_IDENTIFIER = new HiddenKey("method");
public static final Property METHOD_PROPERTY;

private static final DynamicObjectFactory UNBOUND_METHOD_FACTORY;

static {
final Shape.Allocator allocator = RubyBasicObject.LAYOUT.createAllocator();

ORIGIN_PROPERTY = Property.create(ORIGIN_IDENTIFIER, allocator.locationForType(RubyModule.class, EnumSet.of(LocationModifier.Final, LocationModifier.NonNull)), 0);
METHOD_PROPERTY = Property.create(METHOD_IDENTIFIER, allocator.locationForType(InternalMethod.class, EnumSet.of(LocationModifier.Final, LocationModifier.NonNull)), 0);

final Shape shape = RubyBasicObject.LAYOUT.createShape(UNBOUND_METHOD_TYPE)
.addProperty(ORIGIN_PROPERTY)
.addProperty(METHOD_PROPERTY);

UNBOUND_METHOD_FACTORY = shape.createFactory();
}

public static RubyBasicObject createUnboundMethod(RubyClass rubyClass, RubyModule origin, InternalMethod method) {
return new RubyBasicObject(rubyClass, UNBOUND_METHOD_FACTORY.newInstance(origin, method));
}

public static RubyModule getOrigin(RubyBasicObject method) {
assert method.getDynamicObject().getShape().hasProperty(ORIGIN_IDENTIFIER);
return (RubyModule) ORIGIN_PROPERTY.get(method.getDynamicObject(), true);
}

public static InternalMethod getMethod(RubyBasicObject method) {
assert method.getDynamicObject().getShape().hasProperty(METHOD_IDENTIFIER);
return (InternalMethod) METHOD_PROPERTY.get(method.getDynamicObject(), true);
}

@CoreMethod(names = "==", required = 1)
public abstract static class EqualNode extends CoreMethodArrayArgumentsNode {

public EqualNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
boolean equal(RubyUnboundMethod self, RubyUnboundMethod other) {
return self.getMethod() == other.getMethod() && self.getOrigin() == other.getOrigin();
@Specialization(guards = "isRubyUnboundMethod(other)")
boolean equal(RubyBasicObject self, RubyBasicObject other) {
return getMethod(self) == getMethod(other) && getOrigin(self) == getOrigin(other);
}

@Specialization(guards = "!isRubyUnboundMethod(other)")
boolean equal(RubyUnboundMethod self, Object other) {
boolean equal(RubyBasicObject self, Object other) {
return false;
}

@@ -57,8 +104,8 @@ public ArityNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public int arity(RubyUnboundMethod method) {
return method.getMethod().getSharedMethodInfo().getArity().getArityNumber();
public int arity(RubyBasicObject method) {
return getMethod(method).getSharedMethodInfo().getArity().getArityNumber();
}

}
@@ -81,10 +128,10 @@ private RubyClass metaClass(VirtualFrame frame, Object object) {
}

@Specialization
public RubyMethod bind(VirtualFrame frame, RubyUnboundMethod unboundMethod, Object object) {
public RubyBasicObject bind(VirtualFrame frame, RubyBasicObject unboundMethod, Object object) {
CompilerDirectives.transferToInterpreter();

RubyModule module = unboundMethod.getMethod().getDeclaringModule();
RubyModule module = getMethod(unboundMethod).getDeclaringModule();
// the (redundant) instanceof is to satisfy FindBugs with the following cast
if (module instanceof RubyClass && !ModuleOperations.canBindMethodTo(module, metaClass(frame, object))) {
CompilerDirectives.transferToInterpreter();
@@ -95,7 +142,7 @@ public RubyMethod bind(VirtualFrame frame, RubyUnboundMethod unboundMethod, Obje
}
}

return new RubyMethod(getContext().getCoreLibrary().getMethodClass(), object, unboundMethod.getMethod());
return MethodNodes.createMethod(getContext().getCoreLibrary().getMethodClass(), object, getMethod(unboundMethod));
}

}
@@ -108,8 +155,8 @@ public NameNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public RubySymbol name(RubyUnboundMethod unboundMethod) {
return getContext().getSymbol(unboundMethod.getMethod().getName());
public RubySymbol name(RubyBasicObject unboundMethod) {
return getContext().getSymbol(getMethod(unboundMethod).getName());
}

}
@@ -123,8 +170,8 @@ public OriginNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public RubyModule origin(RubyUnboundMethod unboundMethod) {
return unboundMethod.getOrigin();
public RubyModule origin(RubyBasicObject unboundMethod) {
return getOrigin(unboundMethod);
}

}
@@ -137,8 +184,8 @@ public OwnerNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public RubyModule owner(RubyUnboundMethod unboundMethod) {
return unboundMethod.getMethod().getDeclaringModule();
public RubyModule owner(RubyBasicObject unboundMethod) {
return getMethod(unboundMethod).getDeclaringModule();
}

}
@@ -152,8 +199,8 @@ public ParametersNode(RubyContext context, SourceSection sourceSection) {

@TruffleBoundary
@Specialization
public RubyArray parameters(RubyUnboundMethod method) {
final ArgsNode argsNode = method.getMethod().getSharedMethodInfo().getParseTree().findFirstChild(ArgsNode.class);
public RubyArray parameters(RubyBasicObject method) {
final ArgsNode argsNode = getMethod(method).getSharedMethodInfo().getParseTree().findFirstChild(ArgsNode.class);

final ArgumentDescriptor[] argsDesc = Helpers.argsNodeToArgumentDescriptors(argsNode);

@@ -172,14 +219,14 @@ public SourceLocationNode(RubyContext context, SourceSection sourceSection) {

@TruffleBoundary
@Specialization
public Object sourceLocation(RubyUnboundMethod unboundMethod) {
SourceSection sourceSection = unboundMethod.getMethod().getSharedMethodInfo().getSourceSection();
public Object sourceLocation(RubyBasicObject unboundMethod) {
SourceSection sourceSection = getMethod(unboundMethod).getSharedMethodInfo().getSourceSection();

if (sourceSection instanceof NullSourceSection) {
return nil();
} else {
RubyString file = getContext().makeString(sourceSection.getSource().getName());
return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(),
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(),
file, sourceSection.getStartLine());
}
}
Original file line number Diff line number Diff line change
@@ -40,25 +40,25 @@ public AppendManyNode(RubyContext context, SourceSection sourceSection) {

@Specialization(guards = "isEmpty(array)")
public RubyArray appendManyEmpty(RubyArray array, int otherSize, int[] other) {
array.setStore(Arrays.copyOf(other, otherSize), otherSize);
ArrayNodes.setStore(array, Arrays.copyOf(other, otherSize), otherSize);
return array;
}

@Specialization(guards = "isEmpty(array)")
public RubyArray appendManyEmpty(RubyArray array, int otherSize, long[] other) {
array.setStore(Arrays.copyOf(other, otherSize), otherSize);
ArrayNodes.setStore(array, Arrays.copyOf(other, otherSize), otherSize);
return array;
}

@Specialization(guards = "isEmpty(array)")
public RubyArray appendManyEmpty(RubyArray array, int otherSize, double[] other) {
array.setStore(Arrays.copyOf(other, otherSize), otherSize);
ArrayNodes.setStore(array, Arrays.copyOf(other, otherSize), otherSize);
return array;
}

@Specialization(guards = "isEmpty(array)")
public RubyArray appendManyEmpty(RubyArray array, int otherSize, Object[] other) {
array.setStore(Arrays.copyOf(other, otherSize), otherSize);
ArrayNodes.setStore(array, Arrays.copyOf(other, otherSize), otherSize);
return array;
}

@@ -67,39 +67,39 @@ public RubyArray appendManyEmpty(RubyArray array, int otherSize, Object[] other)
@Specialization(guards = "isIntegerFixnum(array)")
public RubyArray appendManySameType(RubyArray array, int otherSize, int[] other,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendManySameTypeGeneric(array, ArrayMirror.reflect((int[]) array.getStore()),
appendManySameTypeGeneric(array, ArrayMirror.reflect((int[]) ArrayNodes.getStore(array)),
otherSize, ArrayMirror.reflect(other), extendProfile);
return array;
}

@Specialization(guards = "isLongFixnum(array)")
public RubyArray appendManySameType(RubyArray array, int otherSize, long[] other,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendManySameTypeGeneric(array, ArrayMirror.reflect((long[]) array.getStore()),
appendManySameTypeGeneric(array, ArrayMirror.reflect((long[]) ArrayNodes.getStore(array)),
otherSize, ArrayMirror.reflect(other), extendProfile);
return array;
}

@Specialization(guards = "isFloat(array)")
public RubyArray appendManySameType(RubyArray array, int otherSize, double[] other,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendManySameTypeGeneric(array, ArrayMirror.reflect((double[]) array.getStore()),
appendManySameTypeGeneric(array, ArrayMirror.reflect((double[]) ArrayNodes.getStore(array)),
otherSize, ArrayMirror.reflect(other), extendProfile);
return array;
}

@Specialization(guards = "isObject(array)")
public RubyArray appendManySameType(RubyArray array, int otherSize, Object[] other,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendManySameTypeGeneric(array, ArrayMirror.reflect((Object[]) array.getStore()),
appendManySameTypeGeneric(array, ArrayMirror.reflect((Object[]) ArrayNodes.getStore(array)),
otherSize, ArrayMirror.reflect(other), extendProfile);
return array;
}

public void appendManySameTypeGeneric(RubyArray array, ArrayMirror storeMirror,
int otherSize, ArrayMirror otherStoreMirror,
ConditionProfile extendProfile) {
final int oldSize = array.getSize();
final int oldSize = ArrayNodes.getSize(array);
final int newSize = oldSize + otherSize;

final ArrayMirror newStoreMirror;
@@ -111,7 +111,7 @@ public void appendManySameTypeGeneric(RubyArray array, ArrayMirror storeMirror,
}

otherStoreMirror.copyTo(newStoreMirror, 0, oldSize, otherSize);
array.setStore(newStoreMirror.getArray(), newSize);
ArrayNodes.setStore(array, newStoreMirror.getArray(), newSize);
}

// Append something else into an Object[]
@@ -139,10 +139,10 @@ public RubyArray appendManyBoxIntoObject(RubyArray array, int otherSize, double[

public void appendManyBoxIntoObjectGeneric(RubyArray array, int otherSize, ArrayMirror otherStoreMirror,
ConditionProfile extendProfile) {
final int oldSize = array.getSize();
final int oldSize = ArrayNodes.getSize(array);
final int newSize = oldSize + otherSize;

final Object[] oldStore = (Object[]) array.getStore();
final Object[] oldStore = (Object[]) ArrayNodes.getStore(array);
final Object[] newStore;

if (extendProfile.profile(newSize > oldStore.length)) {
@@ -152,82 +152,82 @@ public void appendManyBoxIntoObjectGeneric(RubyArray array, int otherSize, Array
}

otherStoreMirror.copyTo(newStore, 0, oldSize, otherSize);
array.setStore(newStore, newSize);
ArrayNodes.setStore(array, newStore, newSize);
}

// Append forcing a generalization from int[] to long[]

@Specialization(guards = "isIntegerFixnum(array)")
public RubyArray appendManyLongIntoInteger(RubyArray array, int otherSize, long[] other) {
final int oldSize = array.getSize();
final int oldSize = ArrayNodes.getSize(array);
final int newSize = oldSize + otherSize;

final int[] oldStore = (int[]) array.getStore();
final int[] oldStore = (int[]) ArrayNodes.getStore(array);
long[] newStore = ArrayUtils.longCopyOf(oldStore, ArrayUtils.capacity(oldStore.length, newSize));

System.arraycopy(other, 0, newStore, oldSize, otherSize);

array.setStore(newStore, newSize);
ArrayNodes.setStore(array, newStore, newSize);
return array;
}

// Append forcing a generalization to Object[]

@Specialization(guards = "isIntegerFixnum(array)")
public RubyArray appendManyGeneralizeIntegerDouble(RubyArray array, int otherSize, double[] other) {
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((int[]) array.getStore()),
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((int[]) ArrayNodes.getStore(array)),
otherSize, ArrayMirror.reflect(other));
return array;
}

@Specialization(guards = "isIntegerFixnum(array)")
public RubyArray appendManyGeneralizeIntegerDouble(RubyArray array, int otherSize, Object[] other) {
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((int[]) array.getStore()),
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((int[]) ArrayNodes.getStore(array)),
otherSize, ArrayMirror.reflect(other));
return array;
}

@Specialization(guards = "isLongFixnum(array)")
public RubyArray appendManyGeneralizeLongDouble(RubyArray array, int otherSize, double[] other) {
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((long[]) array.getStore()),
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((long[]) ArrayNodes.getStore(array)),
otherSize, ArrayMirror.reflect(other));
return array;
}

@Specialization(guards = "isLongFixnum(array)")
public RubyArray appendManyGeneralizeLongDouble(RubyArray array, int otherSize, Object[] other) {
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((long[]) array.getStore()),
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((long[]) ArrayNodes.getStore(array)),
otherSize, ArrayMirror.reflect(other));
return array;
}

@Specialization(guards = "isFloat(array)")
public RubyArray appendManyGeneralizeDoubleInteger(RubyArray array, int otherSize, int[] other) {
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((double[]) array.getStore()),
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((double[]) ArrayNodes.getStore(array)),
otherSize, ArrayMirror.reflect(other));
return array;
}

@Specialization(guards = "isFloat(array)")
public RubyArray appendManyGeneralizeDoubleLong(RubyArray array, int otherSize, long[] other) {
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((double[]) array.getStore()),
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((double[]) ArrayNodes.getStore(array)),
otherSize, ArrayMirror.reflect(other));
return array;
}

@Specialization(guards = "isFloat(array)")
public RubyArray appendManyGeneralizeDoubleObject(RubyArray array, int otherSize, Object[] other) {
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((double[]) array.getStore()),
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((double[]) ArrayNodes.getStore(array)),
otherSize, ArrayMirror.reflect(other));
return array;
}

public void appendManyGeneralizeGeneric(RubyArray array, ArrayMirror storeMirror, int otherSize, ArrayMirror otherStoreMirror) {
final int oldSize = array.getSize();
final int oldSize = ArrayNodes.getSize(array);
final int newSize = oldSize + otherSize;
Object[] newStore = storeMirror.getBoxedCopy(ArrayUtils.capacity(storeMirror.getLength(), newSize));
otherStoreMirror.copyTo(newStore, 0, oldSize, otherSize);
array.setStore(newStore, newSize);
ArrayNodes.setStore(array, newStore, newSize);
}

}
Original file line number Diff line number Diff line change
@@ -37,25 +37,25 @@ public AppendOneNode(RubyContext context, SourceSection sourceSection) {

@Specialization(guards = "isEmpty(array)")
public RubyArray appendOneEmpty(RubyArray array, int value) {
array.setStore(new int[]{value}, 1);
ArrayNodes.setStore(array, new int[]{value}, 1);
return array;
}

@Specialization(guards = "isEmpty(array)")
public RubyArray appendOneEmpty(RubyArray array, long value) {
array.setStore(new long[]{value}, 1);
ArrayNodes.setStore(array, new long[]{value}, 1);
return array;
}

@Specialization(guards = "isEmpty(array)")
public RubyArray appendOneEmpty(RubyArray array, double value) {
array.setStore(new double[]{value}, 1);
ArrayNodes.setStore(array, new double[]{value}, 1);
return array;
}

@Specialization(guards = "isEmpty(array)")
public RubyArray appendOneEmpty(RubyArray array, Object value) {
array.setStore(new Object[]{value}, 1);
ArrayNodes.setStore(array, new Object[]{value}, 1);
return array;
}

@@ -64,33 +64,33 @@ public RubyArray appendOneEmpty(RubyArray array, Object value) {
@Specialization(guards = "isIntegerFixnum(array)")
public RubyArray appendOneSameType(RubyArray array, int value,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendOneSameTypeGeneric(array, ArrayMirror.reflect((int[]) array.getStore()), value, extendProfile);
appendOneSameTypeGeneric(array, ArrayMirror.reflect((int[]) ArrayNodes.getStore(array)), value, extendProfile);
return array;
}

@Specialization(guards = "isLongFixnum(array)")
public RubyArray appendOneSameType(RubyArray array, long value,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendOneSameTypeGeneric(array, ArrayMirror.reflect((long[]) array.getStore()), value, extendProfile);
appendOneSameTypeGeneric(array, ArrayMirror.reflect((long[]) ArrayNodes.getStore(array)), value, extendProfile);
return array;
}

@Specialization(guards = "isFloat(array)")
public RubyArray appendOneSameType(RubyArray array, double value,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendOneSameTypeGeneric(array, ArrayMirror.reflect((double[]) array.getStore()), value, extendProfile);
appendOneSameTypeGeneric(array, ArrayMirror.reflect((double[]) ArrayNodes.getStore(array)), value, extendProfile);
return array;
}

@Specialization(guards = "isObject(array)")
public RubyArray appendOneSameType(RubyArray array, Object value,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendOneSameTypeGeneric(array, ArrayMirror.reflect((Object[]) array.getStore()), value, extendProfile);
appendOneSameTypeGeneric(array, ArrayMirror.reflect((Object[]) ArrayNodes.getStore(array)), value, extendProfile);
return array;
}

public void appendOneSameTypeGeneric(RubyArray array, ArrayMirror storeMirror, Object value, ConditionProfile extendProfile) {
final int oldSize = array.getSize();
final int oldSize = ArrayNodes.getSize(array);
final int newSize = oldSize + 1;

final ArrayMirror newStoreMirror;
@@ -102,50 +102,50 @@ public void appendOneSameTypeGeneric(RubyArray array, ArrayMirror storeMirror, O
}

newStoreMirror.set(oldSize, value);
array.setStore(newStoreMirror.getArray(), newSize);
ArrayNodes.setStore(array, newStoreMirror.getArray(), newSize);
}

// Append forcing a generalization from int[] to long[]

@Specialization(guards = "isIntegerFixnum(array)")
public RubyArray appendOneLongIntoInteger(RubyArray array, long value) {
final int oldSize = array.getSize();
final int oldSize = ArrayNodes.getSize(array);
final int newSize = oldSize + 1;

final int[] oldStore = (int[]) array.getStore();
final int[] oldStore = (int[]) ArrayNodes.getStore(array);
long[] newStore = ArrayUtils.longCopyOf(oldStore, ArrayUtils.capacity(oldStore.length, newSize));

newStore[oldSize] = value;
array.setStore(newStore, newSize);
ArrayNodes.setStore(array, newStore, newSize);
return array;
}

// Append forcing a generalization to Object[]

@Specialization(guards = {"isIntegerFixnum(array)", "!isInteger(value)", "!isLong(value)"})
public RubyArray appendOneGeneralizeInteger(RubyArray array, Object value) {
appendOneGeneralizeGeneric(array, ArrayMirror.reflect((int[]) array.getStore()), value);
appendOneGeneralizeGeneric(array, ArrayMirror.reflect((int[]) ArrayNodes.getStore(array)), value);
return array;
}

@Specialization(guards = {"isLongFixnum(array)", "!isInteger(value)", "!isLong(value)"})
public RubyArray appendOneGeneralizeLong(RubyArray array, Object value) {
appendOneGeneralizeGeneric(array, ArrayMirror.reflect((long[]) array.getStore()), value);
appendOneGeneralizeGeneric(array, ArrayMirror.reflect((long[]) ArrayNodes.getStore(array)), value);
return array;
}

@Specialization(guards = {"isFloat(array)", "!isDouble(value)"})
public RubyArray appendOneGeneralizeDouble(RubyArray array, Object value) {
appendOneGeneralizeGeneric(array, ArrayMirror.reflect((double[]) array.getStore()), value);
appendOneGeneralizeGeneric(array, ArrayMirror.reflect((double[]) ArrayNodes.getStore(array)), value);
return array;
}

public void appendOneGeneralizeGeneric(RubyArray array, ArrayMirror storeMirror, Object value) {
final int oldSize = array.getSize();
final int oldSize = ArrayNodes.getSize(array);
final int newSize = oldSize + 1;
Object[] newStore = storeMirror.getBoxedCopy(ArrayUtils.capacity(storeMirror.getLength(), newSize));
newStore[oldSize] = value;
array.setStore(newStore, newSize);
ArrayNodes.setStore(array, newStore, newSize);
}

}
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ public Object ensure(Object store, int length) {
public Object append(Object store, int index, RubyArray array) {
CompilerDirectives.transferToInterpreter();

for (Object value : array.slowToArray()) {
for (Object value : ArrayNodes.slowToArray(array)) {
store = append(store, index, value);
index++;
}
@@ -188,30 +188,30 @@ public Object ensure(Object store, int length) {

@Override
public Object append(Object store, int index, RubyArray array) {
Object otherStore = array.getStore();
Object otherStore = ArrayNodes.getStore(array);

if (otherStore == null) {
return store;
}

if (hasAppendedIntegerArray && otherStore instanceof int[]) {
System.arraycopy(otherStore, 0, store, index, array.getSize());
System.arraycopy(otherStore, 0, store, index, ArrayNodes.getSize(array));
return store;
}

CompilerDirectives.transferToInterpreterAndInvalidate();

if (otherStore instanceof int[]) {
hasAppendedIntegerArray = true;
System.arraycopy(otherStore, 0, store, index, array.getSize());
System.arraycopy(otherStore, 0, store, index, ArrayNodes.getSize(array));
return store;
}

CompilerDirectives.transferToInterpreter();

replace(new ObjectArrayBuilderNode(getContext(), expectedLength));
final Object[] newStore = ArrayUtils.box((int[]) store);
System.arraycopy(otherStore, 0, newStore, index, array.getSize());
System.arraycopy(otherStore, 0, newStore, index, ArrayNodes.getSize(array));

return newStore;
}
@@ -422,22 +422,22 @@ public Object ensure(Object store, int length) {

@Override
public Object append(Object store, int index, RubyArray array) {
Object otherStore = array.getStore();
Object otherStore = ArrayNodes.getStore(array);

if (otherStore == null) {
return store;
}

if (hasAppendedObjectArray && otherStore instanceof Object[]) {
System.arraycopy(otherStore, 0, store, index, array.getSize());
System.arraycopy(otherStore, 0, store, index, ArrayNodes.getSize(array));
return store;
}

if (hasAppendedIntArray && otherStore instanceof int[]) {
final Object[] objectStore = (Object[]) store;
final int[] otherIntStore = (int[]) otherStore;

for (int n = 0; n < array.getSize(); n++) {
for (int n = 0; n < ArrayNodes.getSize(array); n++) {
objectStore[index + n] = otherIntStore[n];
}

@@ -448,23 +448,23 @@ public Object append(Object store, int index, RubyArray array) {

if (otherStore instanceof int[]) {
hasAppendedIntArray = true;
for (int n = 0; n < array.getSize(); n++) {
for (int n = 0; n < ArrayNodes.getSize(array); n++) {
((Object[]) store)[index + n] = ((int[]) otherStore)[n];
}

return store;
}

if (otherStore instanceof long[]) {
for (int n = 0; n < array.getSize(); n++) {
for (int n = 0; n < ArrayNodes.getSize(array); n++) {
((Object[]) store)[index + n] = ((long[]) otherStore)[n];
}

return store;
}

if (otherStore instanceof double[]) {
for (int n = 0; n < array.getSize(); n++) {
for (int n = 0; n < ArrayNodes.getSize(array); n++) {
((Object[]) store)[index + n] = ((double[]) otherStore)[n];
}

@@ -473,11 +473,11 @@ public Object append(Object store, int index, RubyArray array) {

if (otherStore instanceof Object[]) {
hasAppendedObjectArray = true;
System.arraycopy(otherStore, 0, store, index, array.getSize());
System.arraycopy(otherStore, 0, store, index, ArrayNodes.getSize(array));
return store;
}

throw new UnsupportedOperationException(array.getStore().getClass().getName());
throw new UnsupportedOperationException(ArrayNodes.getStore(array).getClass().getName());
}

@Override
Original file line number Diff line number Diff line change
@@ -52,9 +52,9 @@ private RubyArray executeSingle(VirtualFrame frame, Object store, int length) {
if (childObject instanceof RubyArray) {
appendArrayProfile.enter();
final RubyArray childArray = (RubyArray) childObject;
store = arrayBuilderNode.ensure(store, length + childArray.getSize());
store = arrayBuilderNode.ensure(store, length + ArrayNodes.getSize(childArray));
store = arrayBuilderNode.append(store, length, childArray);
length += childArray.getSize();
length += ArrayNodes.getSize(childArray);
} else {
appendObjectProfile.enter();
store = arrayBuilderNode.ensure(store, length + 1);
@@ -72,9 +72,9 @@ private RubyArray executeRubyArray(VirtualFrame frame, Object store, int length)
if (childObject instanceof RubyArray) {
appendArrayProfile.enter();
final RubyArray childArray = (RubyArray) childObject;
store = arrayBuilderNode.ensure(store, length + childArray.getSize());
store = arrayBuilderNode.ensure(store, length + ArrayNodes.getSize(childArray));
store = arrayBuilderNode.append(store, length, childArray);
length += childArray.getSize();
length += ArrayNodes.getSize(childArray);
} else {
appendObjectProfile.enter();
store = arrayBuilderNode.ensure(store, length + 1);
Original file line number Diff line number Diff line change
@@ -42,46 +42,46 @@ public RubyArray getHeadNull(RubyArray array) {
public RubyArray getHeadIntegerFixnum(RubyArray array) {
CompilerDirectives.transferToInterpreter();

if (index >= array.getSize()) {
if (index >= ArrayNodes.getSize(array)) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass());
} else {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), ArrayUtils.extractRange((int[]) array.getStore(), 0, array.getSize() - index), array.getSize() - index);
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), ArrayUtils.extractRange((int[]) ArrayNodes.getStore(array), 0, ArrayNodes.getSize(array) - index), ArrayNodes.getSize(array) - index);
}
}

@Specialization(guards = "isLongFixnum(array)")
public RubyArray geHeadLongFixnum(RubyArray array) {
CompilerDirectives.transferToInterpreter();

if (index >= array.getSize()) {
if (index >= ArrayNodes.getSize(array)) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass());
} else {
final int size = array.getSize() - index;
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), ArrayUtils.extractRange((long[]) array.getStore(), 0, size), size);
final int size = ArrayNodes.getSize(array) - index;
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), ArrayUtils.extractRange((long[]) ArrayNodes.getStore(array), 0, size), size);
}
}

@Specialization(guards = "isFloat(array)")
public RubyArray getHeadFloat(RubyArray array) {
CompilerDirectives.transferToInterpreter();

if (index >= array.getSize()) {
if (index >= ArrayNodes.getSize(array)) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass());
} else {
final int size = array.getSize() - index;
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), ArrayUtils.extractRange((double[]) array.getStore(), 0, size), size);
final int size = ArrayNodes.getSize(array) - index;
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), ArrayUtils.extractRange((double[]) ArrayNodes.getStore(array), 0, size), size);
}
}

@Specialization(guards = "isObject(array)")
public RubyArray getHeadObject(RubyArray array) {
CompilerDirectives.transferToInterpreter();

if (index >= array.getSize()) {
if (index >= ArrayNodes.getSize(array)) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass());
} else {
final int size = array.getSize() - index;
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), ArrayUtils.extractRange((Object[]) array.getStore(), 0, size), size);
final int size = ArrayNodes.getSize(array) - index;
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), ArrayUtils.extractRange((Object[]) ArrayNodes.getStore(array), 0, size), size);
}
}

Original file line number Diff line number Diff line change
@@ -41,22 +41,22 @@ public RubyArray dupNull(RubyArray from) {

@Specialization(guards = "isIntegerFixnum(from)")
public RubyArray dupIntegerFixnum(RubyArray from) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), Arrays.copyOf((int[]) from.getStore(), from.getSize()), from.getSize());
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), Arrays.copyOf((int[]) ArrayNodes.getStore(from), ArrayNodes.getSize(from)), ArrayNodes.getSize(from));
}

@Specialization(guards = "isLongFixnum(from)")
public RubyArray dupLongFixnum(RubyArray from) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), Arrays.copyOf((long[]) from.getStore(), from.getSize()), from.getSize());
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), Arrays.copyOf((long[]) ArrayNodes.getStore(from), ArrayNodes.getSize(from)), ArrayNodes.getSize(from));
}

@Specialization(guards = "isFloat(from)")
public RubyArray dupFloat(RubyArray from) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), Arrays.copyOf((double[]) from.getStore(), from.getSize()), from.getSize());
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), Arrays.copyOf((double[]) ArrayNodes.getStore(from), ArrayNodes.getSize(from)), ArrayNodes.getSize(from));
}

@Specialization(guards = "isObject(from)")
public RubyArray dupObject(RubyArray from) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), Arrays.copyOf((Object[]) from.getStore(), from.getSize()), from.getSize());
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), Arrays.copyOf((Object[]) ArrayNodes.getStore(from), ArrayNodes.getSize(from)), ArrayNodes.getSize(from));
}

}
Original file line number Diff line number Diff line change
@@ -42,43 +42,43 @@ public RubyArray getTailNull(RubyArray array) {
public RubyArray getTailIntegerFixnum(RubyArray array) {
CompilerDirectives.transferToInterpreter();

if (index >= array.getSize()) {
if (index >= ArrayNodes.getSize(array)) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass());
} else {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), ArrayUtils.extractRange((int[]) array.getStore(), index, array.getSize()), array.getSize() - index);
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), ArrayUtils.extractRange((int[]) ArrayNodes.getStore(array), index, ArrayNodes.getSize(array)), ArrayNodes.getSize(array) - index);
}
}

@Specialization(guards = "isLongFixnum(array)")
public RubyArray getTailLongFixnum(RubyArray array) {
CompilerDirectives.transferToInterpreter();

if (index >= array.getSize()) {
if (index >= ArrayNodes.getSize(array)) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass());
} else {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), ArrayUtils.extractRange((long[]) array.getStore(), index, array.getSize()), array.getSize() - index);
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), ArrayUtils.extractRange((long[]) ArrayNodes.getStore(array), index, ArrayNodes.getSize(array)), ArrayNodes.getSize(array) - index);
}
}

@Specialization(guards = "isFloat(array)")
public RubyArray getTailFloat(RubyArray array) {
CompilerDirectives.transferToInterpreter();

if (index >= array.getSize()) {
if (index >= ArrayNodes.getSize(array)) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass());
} else {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), ArrayUtils.extractRange((double[]) array.getStore(), index, array.getSize()), array.getSize() - index);
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), ArrayUtils.extractRange((double[]) ArrayNodes.getStore(array), index, ArrayNodes.getSize(array)), ArrayNodes.getSize(array) - index);
}
}

@Specialization(guards = "isObject(array)")
public RubyArray getTailObject(RubyArray array) {
CompilerDirectives.transferToInterpreter();

if (index >= array.getSize()) {
if (index >= ArrayNodes.getSize(array)) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass());
} else {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), ArrayUtils.extractRange((Object[]) array.getStore(), index, array.getSize()), array.getSize() - index);
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), ArrayUtils.extractRange((Object[]) ArrayNodes.getStore(array), index, ArrayNodes.getSize(array)), ArrayNodes.getSize(array) - index);
}
}

Original file line number Diff line number Diff line change
@@ -15,109 +15,109 @@
public class ArrayGuards {

public static boolean isEmpty(RubyArray array) {
return array.getSize() == 0;
return ArrayNodes.getSize(array) == 0;
}

public static boolean isOtherEmpty(RubyArray array, RubyArray other) {
return other.getSize() == 0;
return ArrayNodes.getSize(other) == 0;
}

public static boolean isNull(RubyArray array) {
return array.getStore() == null;
return ArrayNodes.getStore(array) == null;
}

public static boolean isNullOrEmpty(RubyArray array) {
return array.getStore() == null || array.getSize() == 0;
return ArrayNodes.getStore(array) == null || ArrayNodes.getSize(array) == 0;
}

public static boolean isIntegerFixnum(RubyArray array) {
return array.getStore() instanceof int[];
return ArrayNodes.getStore(array) instanceof int[];
}

public static boolean isLongFixnum(RubyArray array) {
return array.getStore() instanceof long[];
return ArrayNodes.getStore(array) instanceof long[];
}

public static boolean isFloat(RubyArray array) {
return array.getStore() instanceof double[];
return ArrayNodes.getStore(array) instanceof double[];
}

public static boolean isObject(RubyArray array) {
return array.getStore() instanceof Object[];
return ArrayNodes.getStore(array) instanceof Object[];
}

public static boolean isOtherNull(RubyArray array, RubyArray other) {
return other.getStore() == null;
return ArrayNodes.getStore(other) == null;
}

public static boolean isOtherIntegerFixnum(RubyArray array, RubyArray other) {
return other.getStore() instanceof int[];
return ArrayNodes.getStore(other) instanceof int[];
}

public static boolean isOtherLongFixnum(RubyArray array, RubyArray other) {
return other.getStore() instanceof long[];
return ArrayNodes.getStore(other) instanceof long[];
}

public static boolean isOtherFloat(RubyArray array, RubyArray other) {
return other.getStore() instanceof double[];
return ArrayNodes.getStore(other) instanceof double[];
}

public static boolean isOtherObject(RubyArray array, RubyArray other) {
return other.getStore() instanceof Object[];
return ArrayNodes.getStore(other) instanceof Object[];
}

public static boolean areBothNull(RubyArray a, RubyArray b) {
return a.getStore() == null && b.getStore() == null;
return ArrayNodes.getStore(a) == null && ArrayNodes.getStore(b) == null;
}

public static boolean areBothIntegerFixnum(RubyArray a, RubyArray b) {
return a.getStore() instanceof int[] && b.getStore() instanceof int[];
return ArrayNodes.getStore(a) instanceof int[] && ArrayNodes.getStore(b) instanceof int[];
}

public static boolean areBothIntegerFixnum(RubyArray array, RubyRange.IntegerFixnumRange range, RubyArray other) {
return array.getStore() instanceof int[] && other.getStore() instanceof int[];
return ArrayNodes.getStore(array) instanceof int[] && ArrayNodes.getStore(other) instanceof int[];
}

public static boolean areBothLongFixnum(RubyArray a, RubyArray b) {
return a.getStore() instanceof long[] && b.getStore() instanceof long[];
return ArrayNodes.getStore(a) instanceof long[] && ArrayNodes.getStore(b) instanceof long[];
}

public static boolean areBothFloat(RubyArray a, RubyArray b) {
return a.getStore() instanceof double[] && b.getStore() instanceof double[];
return ArrayNodes.getStore(a) instanceof double[] && ArrayNodes.getStore(b) instanceof double[];
}

public static boolean areBothObject(RubyArray a, RubyArray b) {
return a.getStore() instanceof Object[] && b.getStore() instanceof Object[];
return ArrayNodes.getStore(a) instanceof Object[] && ArrayNodes.getStore(b) instanceof Object[];
}

// New names being used for the new primitive nodes - old guards will be removed over time

public static boolean isNullArray(RubyArray array) {
return array.getStore() == null;
return ArrayNodes.getStore(array) == null;
}

public static boolean isIntArray(RubyArray array) {
return array.getStore() instanceof int[];
return ArrayNodes.getStore(array) instanceof int[];
}

public static boolean isLongArray(RubyArray array) {
return array.getStore() instanceof long[];
return ArrayNodes.getStore(array) instanceof long[];
}

public static boolean isDoubleArray(RubyArray array) {
return array.getStore() instanceof double[];
return ArrayNodes.getStore(array) instanceof double[];
}

public static boolean isObjectArray(RubyArray array) {
return array.getStore() instanceof Object[];
return ArrayNodes.getStore(array) instanceof Object[];
}

public static boolean isOtherSingleIntegerFixnumArray(RubyArray array, Object[] others) {
return others.length == 1 && others[0] instanceof RubyArray && ((RubyArray) others[0]).getStore() instanceof int[];
return others.length == 1 && others[0] instanceof RubyArray && ArrayNodes.getStore(((RubyArray) others[0])) instanceof int[];
}

public static boolean isOtherSingleObjectArray(RubyArray array, Object[] others) {
return others.length == 1 && others[0] instanceof RubyArray && ((RubyArray) others[0]).getStore() instanceof Object[];
return others.length == 1 && others[0] instanceof RubyArray && ArrayNodes.getStore(((RubyArray) others[0])) instanceof Object[];
}

public static boolean isArgsLengthTwo(RubyArray array, Object[] others) {
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ protected RubyArray makeGeneric(VirtualFrame frame, Object[] alreadyExecuted) {
}
}

return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(), executedValues);
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), executedValues);
}

@Override
@@ -236,8 +236,8 @@ public RubyArray executeRubyArray(VirtualFrame frame) {
executedValues[n] = values[n].execute(frame);
}

final RubyArray array = RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(), executedValues);
final Object store = array.getStore();
final RubyArray array = ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), executedValues);
final Object store = ArrayNodes.getStore(array);

if (store == null) {
replace(new EmptyArrayLiteralNode(getContext(), getSourceSection(), values));
Loading