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: 5cfdf5a32c45
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d963671a2dbe
Choose a head ref

Commits on Aug 21, 2015

  1. Copy the full SHA
    06e4175 View commit details
  2. implement bigmath .exp

    ahorek committed Aug 21, 2015
    Copy the full SHA
    b6f29ef View commit details
  3. Copy the full SHA
    9c1fe2e View commit details
  4. implement bigdecimal .to_r

    ahorek committed Aug 21, 2015
    Copy the full SHA
    d2a1a93 View commit details
  5. Copy the full SHA
    b0dac00 View commit details
  6. BigDecimal('0.1').coerce(0.1) returns two bigdecimals not floats

    BigDecimal('0.1').coerce(10**(-1)) fix type error
    BigDecimal('0.1') == ((10**(-1))) should be true
    ahorek committed Aug 21, 2015
    Copy the full SHA
    73764ea View commit details
  7. more specs are passing

    ahorek committed Aug 21, 2015
    Copy the full SHA
    ac39239 View commit details
  8. Copy the full SHA
    fc5be98 View commit details
  9. fix log positive infinity

    ahorek committed Aug 21, 2015
    Copy the full SHA
    efd173e View commit details
  10. increase precision

    ahorek committed Aug 21, 2015
    Copy the full SHA
    e1ad735 View commit details
  11. input should be numeric

    ahorek committed Aug 21, 2015
    Copy the full SHA
    52db7e9 View commit details
  12. Copy the full SHA
    43da800 View commit details
  13. Fixes #1328. Encoding of symbol literals does not respect the encodin…

    …g of the source file
    enebo committed Aug 21, 2015
    Copy the full SHA
    e590e5d View commit details
  14. Copy the full SHA
    de4aa81 View commit details
  15. Copy the full SHA
    1778496 View commit details
  16. Copy the full SHA
    d2c5a62 View commit details
  17. Copy the full SHA
    f9e48bb View commit details
  18. Merge pull request #3271 from ahorek/bigdecimal_and_bigmath

    bigdecimal & bigmath
    enebo committed Aug 21, 2015
    Copy the full SHA
    3584f55 View commit details
  19. Copy the full SHA
    dbe8640 View commit details
  20. Copy the full SHA
    003e871 View commit details
  21. Update to psych 2.0.15.

    headius committed Aug 21, 2015
    Copy the full SHA
    bd35928 View commit details
  22. Copy the full SHA
    209f584 View commit details
  23. Copy the full SHA
    3d7d650 View commit details
  24. Copy the full SHA
    092162f View commit details
  25. Copy the full SHA
    5b1812d View commit details
  26. Copy the full SHA
    21088d4 View commit details
  27. Copy the full SHA
    d56b47e View commit details
  28. Copy the full SHA
    f8a77f4 View commit details
  29. Copy the full SHA
    469a186 View commit details

Commits on Aug 22, 2015

  1. Copy the full SHA
    329425e View commit details
  2. Copy the full SHA
    422e8cf View commit details
  3. Copy the full SHA
    7f602ff View commit details
  4. Copy the full SHA
    e645219 View commit details
  5. Merge branch 'master' into truffle-new-require

    Conflicts:
    	truffle/src/main/java/org/jruby/truffle/runtime/RubyContext.java
    	truffle/src/main/java/org/jruby/truffle/runtime/loader/FeatureLoader.java
    chrisseaton committed Aug 22, 2015
    Copy the full SHA
    6a74df6 View commit details
  6. Copy the full SHA
    0f8333d View commit details
  7. Copy the full SHA
    d963671 View commit details
Showing with 1,266 additions and 954 deletions.
  1. +1 −0 .travis.yml
  2. +40 −5 core/src/main/java/org/jruby/ext/bigdecimal/RubyBigDecimal.java
  3. +16 −0 core/src/main/java/org/jruby/parser/ParserSupport.java
  4. +7 −9 core/src/main/java/org/jruby/parser/RubyParser.java
  5. +4 −6 core/src/main/java/org/jruby/parser/RubyParser.y
  6. +0 −3 core/src/main/java/org/jruby/util/cli/Options.java
  7. +8 −0 core/src/main/java/org/jruby/util/io/EncodingUtils.java
  8. +50 −12 core/src/main/ruby/jruby/bigdecimal.rb
  9. +1 −1 core/src/main/ruby/jruby/jruby.rb
  10. +1 −0 core/src/test/java/org/jruby/test/MainTestSuite.java
  11. +32 −0 core/src/test/java/org/jruby/test/TestEncodingAPI.java
  12. +3 −3 lib/pom.rb
  13. +5 −5 lib/pom.xml
  14. +1 −15 lib/ruby/stdlib/bigdecimal/math.rb
  15. +1 −1 lib/ruby/stdlib/jruby/compiler.rb
  16. +1 −21 test/mri/excludes/TestBigDecimal.rb
  17. +3 −3 truffle/src/main/java/org/jruby/truffle/nodes/arguments/ReadRestArgumentNode.java
  18. +1 −1 truffle/src/main/java/org/jruby/truffle/nodes/cast/ArrayCastNode.java
  19. +2 −1 truffle/src/main/java/org/jruby/truffle/nodes/cast/SingleValueCastNode.java
  20. +3 −3 truffle/src/main/java/org/jruby/truffle/nodes/cast/SplatCastNode.java
  21. +2 −2 truffle/src/main/java/org/jruby/truffle/nodes/control/WhenSplatNode.java
  22. +2 −2 truffle/src/main/java/org/jruby/truffle/nodes/core/BindingNodes.java
  23. +2 −1 truffle/src/main/java/org/jruby/truffle/nodes/core/ExceptionNodes.java
  24. +18 −12 truffle/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
  25. +12 −7 truffle/src/main/java/org/jruby/truffle/nodes/core/MatchDataNodes.java
  26. +3 −2 truffle/src/main/java/org/jruby/truffle/nodes/core/MethodNodes.java
  27. +27 −14 truffle/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java
  28. +3 −1 truffle/src/main/java/org/jruby/truffle/nodes/core/ObjectSpaceNodes.java
  29. +3 −2 truffle/src/main/java/org/jruby/truffle/nodes/core/ProcNodes.java
  30. +1 −1 truffle/src/main/java/org/jruby/truffle/nodes/core/RegexpNodes.java
  31. +3 −3 truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
  32. +2 −3 truffle/src/main/java/org/jruby/truffle/nodes/core/TrufflePrimitiveNodes.java
  33. +3 −2 truffle/src/main/java/org/jruby/truffle/nodes/core/UnboundMethodNodes.java
  34. +42 −33 truffle/src/main/java/org/jruby/truffle/nodes/core/array/AppendManyNode.java
  35. +22 −14 truffle/src/main/java/org/jruby/truffle/nodes/core/array/AppendOneNode.java
  36. +2 −1 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayBuilderNode.java
  37. +73 −2 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayLiteralNode.java
  38. +247 −392 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayNodes.java
  39. +0 −46 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayPushNode.java
  40. +3 −1 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayReadDenormalizedNode.java
  41. +3 −1 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayReadSliceDenormalizedNode.java
  42. +9 −17 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayReadSliceNormalizedNode.java
  43. +3 −1 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayWriteDenormalizedNode.java
  44. +38 −19 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayWriteNormalizedNode.java
  45. +8 −4 truffle/src/main/java/org/jruby/truffle/nodes/core/array/EnsureCapacityArrayNode.java
  46. +9 −4 truffle/src/main/java/org/jruby/truffle/nodes/core/array/GeneralizeArrayNode.java
  47. +5 −4 truffle/src/main/java/org/jruby/truffle/nodes/core/array/PopOneNode.java
  48. +9 −4 truffle/src/main/java/org/jruby/truffle/nodes/core/hash/HashNodes.java
  49. +2 −2 truffle/src/main/java/org/jruby/truffle/nodes/exceptions/RescueSplatNode.java
  50. +1 −2 truffle/src/main/java/org/jruby/truffle/nodes/rubinius/FloatPrimitiveNodes.java
  51. +20 −12 truffle/src/main/java/org/jruby/truffle/nodes/rubinius/IOPrimitiveNodes.java
  52. +3 −1 truffle/src/main/java/org/jruby/truffle/nodes/rubinius/StringPrimitiveNodes.java
  53. +9 −5 truffle/src/main/java/org/jruby/truffle/nodes/rubinius/VMPrimitiveNodes.java
  54. +2 −2 truffle/src/main/java/org/jruby/truffle/nodes/supercall/GeneralSuperCallNode.java
  55. +2 −2 truffle/src/main/java/org/jruby/truffle/nodes/supercall/GeneralSuperReCallNode.java
  56. +2 −2 truffle/src/main/java/org/jruby/truffle/nodes/yield/YieldNode.java
  57. +10 −8 truffle/src/main/java/org/jruby/truffle/runtime/RubyContext.java
  58. +12 −221 truffle/src/main/java/org/jruby/truffle/runtime/array/ArrayMirror.java
  59. +46 −0 truffle/src/main/java/org/jruby/truffle/runtime/array/ArrayReflector.java
  60. +66 −0 truffle/src/main/java/org/jruby/truffle/runtime/array/BasicArrayMirror.java
  61. +59 −0 truffle/src/main/java/org/jruby/truffle/runtime/array/DoubleArrayMirror.java
  62. +44 −0 truffle/src/main/java/org/jruby/truffle/runtime/array/EmptyArrayMirror.java
  63. +64 −0 truffle/src/main/java/org/jruby/truffle/runtime/array/IntegerArrayMirror.java
  64. +59 −0 truffle/src/main/java/org/jruby/truffle/runtime/array/LongArrayMirror.java
  65. +55 −0 truffle/src/main/java/org/jruby/truffle/runtime/array/ObjectArrayMirror.java
  66. +7 −2 truffle/src/main/java/org/jruby/truffle/runtime/backtrace/BacktraceFormatter.java
  67. +57 −0 truffle/src/main/java/org/jruby/truffle/runtime/core/ArrayOperations.java
  68. +6 −5 truffle/src/main/java/org/jruby/truffle/runtime/core/CoreLibrary.java
  69. +6 −6 truffle/src/main/java/org/jruby/truffle/runtime/loader/FeatureLoader.java
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -99,6 +99,7 @@ notifications:
on_failure: always
template:
- "%{repository} (%{branch}:%{commit} by %{author}): %{message} (%{build_url})"
skip_join: true

# update jruby-head installed on Travis CI
webhooks:
45 changes: 40 additions & 5 deletions core/src/main/java/org/jruby/ext/bigdecimal/RubyBigDecimal.java
Original file line number Diff line number Diff line change
@@ -465,6 +465,9 @@ private static RubyBigDecimal getVpValue(ThreadContext context, IRubyObject valu
// Converted to a String because some values -inf cannot happen from Java libs
return newInstance(context, context.runtime.getClass("BigDecimal"), value.asString());
}
if ((value instanceof RubyRational) || (value instanceof RubyFloat)) {
return newInstance(context, context.runtime.getClass("BigDecimal"), value, RubyFixnum.newFixnum(context.runtime, RubyFloat.DIG));
}
return cannotBeCoerced(context, value, must);
}

@@ -493,7 +496,10 @@ private static RubyBigDecimal newInstance(Ruby runtime, IRubyObject recv, RubyFl
// precision can be no more than float digits
if (mathContext.getPrecision() > RubyFloat.DIG + 1) throw runtime.newArgumentError("precision too large");

return new RubyBigDecimal(runtime, (RubyClass) recv, new BigDecimal(arg.getDoubleValue(), mathContext));
double dblVal = arg.getDoubleValue();
if(Double.isInfinite(dblVal) || Double.isNaN(dblVal)) throw runtime.newFloatDomainError("NaN");

return new RubyBigDecimal(runtime, (RubyClass) recv, new BigDecimal(dblVal, mathContext));
}

private static RubyBigDecimal newInstance(Ruby runtime, IRubyObject recv, RubyBignum arg, MathContext mathContext) {
@@ -600,7 +606,8 @@ public static RubyBigDecimal newInstance(IRubyObject recv, IRubyObject[] args) {
@JRubyMethod(name = "new", meta = true)
public static RubyBigDecimal newInstance(ThreadContext context, IRubyObject recv, IRubyObject arg) {
if (arg instanceof RubyBigDecimal) return newInstance(context.runtime, recv, (RubyBigDecimal) arg);
if (arg instanceof RubyFloat || arg instanceof RubyRational) throw context.runtime.newArgumentError("can't omit precision for a rational");
if (arg instanceof RubyRational) throw context.runtime.newArgumentError("can't omit precision for a Rational.");
if (arg instanceof RubyFloat) throw context.runtime.newArgumentError("can't omit precision for a Float.");
if (arg instanceof RubyFixnum) return newInstance(context.runtime, recv, (RubyFixnum) arg, MathContext.UNLIMITED);
if (arg instanceof RubyBignum) return newInstance(context.runtime, recv, (RubyBignum) arg, MathContext.UNLIMITED);
return newInstance(context, recv, arg, MathContext.UNLIMITED);
@@ -1192,9 +1199,6 @@ public IRubyObject coerce(IRubyObject other) {

@JRubyMethod
public RubyArray coerce(ThreadContext context, IRubyObject other) {
if (other instanceof RubyFloat) {
return context.runtime.newArray(other, to_f());
}
return context.runtime.newArray(getVpValue(context, other, true), this);
}

@@ -1518,6 +1522,37 @@ public IRubyObject to_int() {
}
}

@JRubyMethod(name = "to_r")
public IRubyObject to_r(ThreadContext context) {
checkFloatDomain();

RubyArray i = split(context);
long sign = (long)i.get(0);
String digits = (String)i.get(1).toString();
long base = (long)i.get(2);
long power = (long)i.get(3);
long denomi_power = power - digits.length();

IRubyObject bigDigits = RubyBignum.newBignum(getRuntime(), (String)digits).op_mul(context, sign);
RubyBignum numerator;
if(bigDigits instanceof RubyBignum) {
numerator = (RubyBignum)bigDigits;
}
else {
numerator = RubyBignum.newBignum(getRuntime(), bigDigits.toString());
}
IRubyObject num, den;
if(denomi_power < 0) {
num = numerator;
den = RubyFixnum.newFixnum(getRuntime(), base).op_mul(context, RubyFixnum.newFixnum(getRuntime(), -denomi_power));
}
else {
num = numerator.op_pow(context, RubyFixnum.newFixnum(getRuntime(), base).op_mul(context, RubyFixnum.newFixnum(getRuntime(), denomi_power)));
den = RubyFixnum.newFixnum(getRuntime(), 1);
}
return RubyRational.newInstance(context, context.runtime.getRational(), num, den);
}

public IRubyObject to_int19() {
return to_int();
}
16 changes: 16 additions & 0 deletions core/src/main/java/org/jruby/parser/ParserSupport.java
Original file line number Diff line number Diff line change
@@ -36,10 +36,13 @@
package org.jruby.parser;

import java.math.BigInteger;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
import java.util.ArrayList;
import java.util.List;
import org.jcodings.Encoding;
import org.jruby.RubyBignum;
import org.jruby.RubyEncoding;
import org.jruby.RubyRegexp;
import org.jruby.ast.*;
import org.jruby.ast.types.ILiteralNode;
@@ -879,6 +882,19 @@ public void setLexer(RubyLexer lexer) {
public DStrNode createDStrNode(ISourcePosition position) {
return new DStrNode(position, lexer.getEncoding());
}

public Node asSymbol(ISourcePosition position, String value) {
// FIXME: tLABEL and identifiers could return ByteList and not String and make String on-demand for method names
// or lvars. This would prevent this re-extraction of bytes from a string with proper charset
try {
Charset charset = lexer.getEncoding().getCharset();
if (charset != null) return new SymbolNode(position, new ByteList(value.getBytes(charset), lexer.getEncoding()));
} catch (UnsupportedCharsetException e) {}

// for non-charsets we are screwed here since bytes will file.encoding and not what we read them as (see above FIXME for
// a much more invasive solution.
return new SymbolNode(position, new ByteList(value.getBytes(), lexer.getEncoding()));
}

public Node asSymbol(ISourcePosition position, Node value) {
return value instanceof StrNode ? new SymbolNode(position, ((StrNode) value).getValue()) :
16 changes: 7 additions & 9 deletions core/src/main/java/org/jruby/parser/RubyParser.java
Original file line number Diff line number Diff line change
@@ -34,7 +34,6 @@
import java.io.IOException;

import org.jruby.ast.ArgsNode;
import org.jruby.ast.ArgumentNode;
import org.jruby.ast.ArrayNode;
import org.jruby.ast.AssignableNode;
import org.jruby.ast.BackRefNode;
@@ -103,7 +102,6 @@
import org.jruby.ast.SelfNode;
import org.jruby.ast.StarNode;
import org.jruby.ast.StrNode;
import org.jruby.ast.SymbolNode;
import org.jruby.ast.TrueNode;
import org.jruby.ast.UnnamedRestArgNode;
import org.jruby.ast.UntilNode;
@@ -147,7 +145,7 @@ public void setWarnings(IRubyWarnings warnings) {
support.setWarnings(warnings);
lexer.setWarnings(warnings);
}
// line 151 "-"
// line 149 "-"
// %token constants
public static final int kCLASS = 257;
public static final int kMODULE = 258;
@@ -4270,7 +4268,7 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
};
states[454] = new ParserState() {
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) {
yyVal = new SymbolNode(lexer.getPosition(), new ByteList(((String)yyVals[0+yyTop]).getBytes(), lexer.getEncoding()));
yyVal = support.asSymbol(lexer.getPosition(), ((String)yyVals[0+yyTop]));
return yyVal;
}
};
@@ -4580,11 +4578,11 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
/* EvStrNode :"#{some expression}"*/
/* Ruby 1.9 allows empty strings as symbols*/
if (((Node)yyVals[-1+yyTop]) == null) {
yyVal = new SymbolNode(lexer.getPosition(), new ByteList(new byte[0], lexer.getEncoding()));
yyVal = support.asSymbol(lexer.getPosition(), "");
} else if (((Node)yyVals[-1+yyTop]) instanceof DStrNode) {
yyVal = new DSymbolNode(((Node)yyVals[-1+yyTop]).getPosition(), ((DStrNode)yyVals[-1+yyTop]));
} else if (((Node)yyVals[-1+yyTop]) instanceof StrNode) {
yyVal = new SymbolNode(((Node)yyVals[-1+yyTop]).getPosition(), ((StrNode)yyVals[-1+yyTop]).getValue());
yyVal = support.asSymbol(((Node)yyVals[-1+yyTop]).getPosition(), ((Node)yyVals[-1+yyTop]));
} else {
yyVal = new DSymbolNode(((Node)yyVals[-1+yyTop]).getPosition());
((DSymbolNode)yyVal).add(((Node)yyVals[-1+yyTop]));
@@ -5250,7 +5248,7 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
};
states[611] = new ParserState() {
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) {
SymbolNode label = new SymbolNode(support.getPosition(((Node)yyVals[0+yyTop])), new ByteList(((String)yyVals[-1+yyTop]).getBytes(), lexer.getEncoding()));
Node label = support.asSymbol(support.getPosition(((Node)yyVals[0+yyTop])), ((String)yyVals[-1+yyTop]));
yyVal = new KeyValuePair<Node,Node>(label, ((Node)yyVals[0+yyTop]));
return yyVal;
}
@@ -5301,7 +5299,7 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
}
};
}
// line 2533 "RubyParser.y"
// line 2531 "RubyParser.y"

/** The parse method use an lexer stream and parse it to an AST node
* structure
@@ -5316,4 +5314,4 @@ public RubyParserResult parse(ParserConfiguration configuration) throws IOExcept
return support.getResult();
}
}
// line 9885 "-"
// line 9883 "-"
10 changes: 4 additions & 6 deletions core/src/main/java/org/jruby/parser/RubyParser.y
Original file line number Diff line number Diff line change
@@ -40,7 +40,6 @@ import org.jruby.ast.BlockArgNode;
import org.jruby.ast.BlockNode;
import org.jruby.ast.BlockPassNode;
import org.jruby.ast.BreakNode;
import org.jruby.ast.CallNode;
import org.jruby.ast.ClassNode;
import org.jruby.ast.ClassVarNode;
import org.jruby.ast.ClassVarAsgnNode;
@@ -99,7 +98,6 @@ import org.jruby.ast.SClassNode;
import org.jruby.ast.SelfNode;
import org.jruby.ast.StarNode;
import org.jruby.ast.StrNode;
import org.jruby.ast.SymbolNode;
import org.jruby.ast.TrueNode;
import org.jruby.ast.UnnamedRestArgNode;
import org.jruby.ast.UntilNode;
@@ -1864,7 +1862,7 @@ literal : numeric {
$$ = $1;
}
| symbol {
$$ = new SymbolNode(lexer.getPosition(), new ByteList($1.getBytes(), lexer.getEncoding()));
$$ = support.asSymbol(lexer.getPosition(), $1);
}
| dsym

@@ -2066,11 +2064,11 @@ dsym : tSYMBEG xstring_contents tSTRING_END {
// EvStrNode :"#{some expression}"
// Ruby 1.9 allows empty strings as symbols
if ($2 == null) {
$$ = new SymbolNode(lexer.getPosition(), new ByteList(new byte[0], lexer.getEncoding()));
$$ = support.asSymbol(lexer.getPosition(), "");
} else if ($2 instanceof DStrNode) {
$$ = new DSymbolNode($2.getPosition(), $<DStrNode>2);
} else if ($2 instanceof StrNode) {
$$ = new SymbolNode($2.getPosition(), $<StrNode>2.getValue());
$$ = support.asSymbol($2.getPosition(), $2);
} else {
$$ = new DSymbolNode($2.getPosition());
$<DSymbolNode>$.add($2);
@@ -2480,7 +2478,7 @@ assoc : arg_value tASSOC arg_value {
$$ = new KeyValuePair<Node,Node>($1, $3);
}
| tLABEL arg_value {
SymbolNode label = new SymbolNode(support.getPosition($2), new ByteList($1.getBytes(), lexer.getEncoding()));
Node label = support.asSymbol(support.getPosition($2), $1);
$$ = new KeyValuePair<Node,Node>(label, $2);
}
| tSTRING_BEG string_contents tLABEL_END arg_value {
3 changes: 0 additions & 3 deletions core/src/main/java/org/jruby/util/cli/Options.java
Original file line number Diff line number Diff line change
@@ -149,9 +149,6 @@ public class Options {
public static final Option<Boolean> TRUFFLE_DISPATCH_METHODMISSING_ALWAYS_CLONED = bool(TRUFFLE, "truffle.call.method_missing_always_cloned", true, "Always clone #method_missing call targets.");
public static final Option<Boolean> TRUFFLE_DISPATCH_METHODMISSING_ALWAYS_INLINED = bool(TRUFFLE, "truffle.call.method_missing_always_inlined", true, "Always inline #method_missing call targets.");

public static final Option<Boolean> TRUFFLE_RANDOMIZE_STORAGE_ARRAY = bool(TRUFFLE, "truffle.randomize_storage.array", false, "Randomize Array storage strategy.");
public static final Option<Integer> TRUFFLE_RANDOMIZE_SEED = integer(TRUFFLE, "truffle.randomize.seed", 0, "Seed for any randomization.");

public static final Option<Boolean> NATIVE_ENABLED = bool(NATIVE, "native.enabled", true, "Enable/disable native code, including POSIX features and C exts.");
public static final Option<Boolean> NATIVE_VERBOSE = bool(NATIVE, "native.verbose", false, "Enable verbose logging of native extension loading.");
public static final Option<Boolean> FFI_COMPILE_DUMP = bool(NATIVE, "ffi.compile.dump", false, "Dump bytecode-generated FFI stubs to console.");
8 changes: 8 additions & 0 deletions core/src/main/java/org/jruby/util/io/EncodingUtils.java
Original file line number Diff line number Diff line change
@@ -1031,10 +1031,12 @@ public static RubyString strConvEncOpts(ThreadContext context, RubyString str, E
EConvResult ret;
int convertedOutput = 0;

// these are in the while clause in MRI
destbytes = newStr.getUnsafeBytes();
int dest = newStr.begin();
dp.p = dest + convertedOutput;
ret = ec.convert(sbytes, sp, start + len, destbytes, dp, dest + olen, 0);

while (ret == EConvResult.DestinationBufferFull) {
int convertedInput = sp.p - start;
int rest = len - convertedInput;
@@ -1048,6 +1050,12 @@ public static RubyString strConvEncOpts(ThreadContext context, RubyString str, E
}
olen += rest < 2 ? 2 : rest;
newStr.ensure(olen);

// these are the while clause in MRI
destbytes = newStr.getUnsafeBytes();
dest = newStr.begin();
dp.p = dest + convertedOutput;
ret = ec.convert(sbytes, sp, start + len, destbytes, dp, dest + olen, 0);
}
ec.close();

62 changes: 50 additions & 12 deletions core/src/main/ruby/jruby/bigdecimal.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
require 'bigdecimal'
require 'bigdecimal/util'

module BigMath
module_function

# call-seq:
# log(decimal, numeric) -> BigDecimal
#
@@ -18,24 +19,27 @@ module BigMath
# BigMath::log(BigMath::E(10), 10).to_s
# #=> "1.000000000000"
#
def log(x, precision)
raise ArgumentError if x.nil?
raise Math::DomainError if x.is_a?(Complex)
raise Math::DomainError if x <= 0
raise ArgumentError unless precision.is_a?(Integer)
raise ArgumentError if precision < 1
return BigDecimal::INFINITY if x == BigDecimal::INFINITY
return BigDecimal::NAN if x.is_a?(BigDecimal) && x.nan?
return BigDecimal::NAN if x.is_a?(Float) && x.nan?
def log(x, prec)
raise ArgumentError if x.nil? || !x.is_a?(Numeric)
raise Math::DomainError if x.is_a?(Complex) || x <= 0
raise ArgumentError unless (true if Integer(prec) rescue false)
prec = prec.to_i
raise ArgumentError if prec < 1
if x.is_a?(BigDecimal) || x.is_a?(Float)
return BigDecimal::INFINITY if x.infinite?
return BigDecimal::NAN if x.nan?
end
x = x.is_a?(Rational) ? x.to_d(Float::DIG) : x.to_d
return BigDecimal::INFINITY if x.infinite?
return BigDecimal::NAN if x.nan?

# this uses the series expansion of the Arctangh (Arc tangens hyperbolicus)
# http://en.wikipedia.org/wiki/Area_hyperbolic_tangent
# where ln(x) = 2 * artanh ((x - 1) / (x + 1))
# d are the elements in the series (getting smaller and smaller)

x = x.to_d
rmpd_double_figures = 16 # from MRI ruby
n = precision + rmpd_double_figures
n = prec + rmpd_double_figures

# offset the calculation to the efficient (0.1)...(10) window
expo = x.exponent
@@ -72,4 +76,38 @@ def log(x, precision)
window_result
end
end

def exp(x, prec)
raise ArgumentError if x.nil? || !x.is_a?(Numeric) || x.is_a?(Complex)
raise ArgumentError unless (true if Integer(prec) rescue false)
prec = prec.to_i
raise ArgumentError if prec < 1
return BigDecimal::NAN if x.is_a?(BigDecimal) && x.nan?
return BigDecimal::NAN if x.is_a?(Float) && x.nan?
x = x.is_a?(Rational) ? x.to_d(Float::DIG) : x.to_d
return BigDecimal::NAN if x.nan?
return x.sign > 0 ? BigDecimal::INFINITY : BigDecimal(0, prec) if x.infinite?

df = BigDecimal.double_fig
n = prec + df
one = BigDecimal(1)
x = -x if neg = x.sign < 0

y = one;
d = y;
i = 1;

while d.nonzero? && ((m = n - (y.exponent - d.exponent).abs) > 0)
m = df if m < df
d = d.mult(x, n)
d = d.div(i, m)
y += d
i += 1;
end
if neg
one.div(y, prec)
else
y.round(prec - y.exponent)
end
end
end
2 changes: 1 addition & 1 deletion core/src/main/ruby/jruby/jruby.rb
Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@ def parse(content = nil, filename = (default_filename = true; '-'), extra_positi
content = content.to_str
filename = filename.to_str unless default_filename

runtime.parse(reference0(content).byte_list, filename, nil, lineno, extra_position_info)
runtime.java_send :parse, [org.jruby.util.ByteList, java.lang.String, org.jruby.runtime.DynamicScope, Java::int, Java::boolean], reference0(content).byte_list, filename, nil, lineno, extra_position_info
end
end
alias ast_for parse
1 change: 1 addition & 0 deletions core/src/test/java/org/jruby/test/MainTestSuite.java
Original file line number Diff line number Diff line change
@@ -92,6 +92,7 @@ public static Test suite() throws Throwable {
suite.addTestSuite(ParameterizedWriterTest.class);
suite.addTestSuite(TestRubyRational.class);
suite.addTestSuite(TestRecursiveCheck.class);
suite.addTestSuite(TestEncodingAPI.class);
// Disabled test due to difficulty of making WeakRef logic deterministic
// suite.addTestSuite(TestRegexpCache.class);
return suite;
32 changes: 32 additions & 0 deletions core/src/test/java/org/jruby/test/TestEncodingAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.jruby.test;

import junit.framework.TestCase;
import org.jcodings.specific.SJISEncoding;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.CompatVersion;

import org.jruby.Ruby;
import org.jruby.RubyInstanceConfig;
import org.jruby.RubyString;
import org.jruby.util.io.EncodingUtils;

public class TestEncodingAPI extends TestCase {
private Ruby runtime;

public TestEncodingAPI(String name) {
super(name);
}

public void setUp() {
runtime = Ruby.newInstance();
}

public void testStrConvEncThatGrows() throws Exception {
String javaStr = "--- こんにちは!";
RubyString rubyStr = RubyString.newString(runtime, javaStr);
rubyStr = EncodingUtils.strConvEnc(runtime.getCurrentContext(), rubyStr, rubyStr.getEncoding(), SJISEncoding.INSTANCE);
assertEquals(rubyStr.getEncoding(), SJISEncoding.INSTANCE);
rubyStr = EncodingUtils.strConvEnc(runtime.getCurrentContext(), rubyStr, SJISEncoding.INSTANCE, UTF8Encoding.INSTANCE);
assertEquals(rubyStr.getEncoding(), UTF8Encoding.INSTANCE);
}
}
6 changes: 3 additions & 3 deletions lib/pom.rb
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ def version
ImportedGem.new( 'minitest', 'minitest.version', true ),
ImportedGem.new( 'test-unit', 'test-unit.version', true ),
ImportedGem.new( 'power_assert', 'power_assert.version', true ),
ImportedGem.new( 'psych', '2.0.14', true ),
ImportedGem.new( 'psych', '2.0.15', true ),
ImportedGem.new( 'json', 'json.version', true ),
ImportedGem.new( 'jar-dependencies', '0.1.15', true )
]
@@ -68,10 +68,10 @@ def to_pathname
# just depends on jruby-core so we are sure the jruby.jar is in place
jar "org.jruby:jruby-core:#{version}", :scope => 'test'

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' )
repository( :url => 'http://rubygems-proxy.torquebox.org/releases',
:id => 'tb-rubygems-releases' )

plugin( :clean,
:filesets => [ { :directory => '${basedir}/ruby/gems/shared/specifications/default',
10 changes: 5 additions & 5 deletions lib/pom.xml
Original file line number Diff line number Diff line change
@@ -125,7 +125,7 @@ DO NOT MODIFIY - GENERATED CODE
<dependency>
<groupId>rubygems</groupId>
<artifactId>psych</artifactId>
<version>2.0.14</version>
<version>2.0.15</version>
<type>gem</type>
<scope>provided</scope>
<exclusions>
@@ -170,14 +170,14 @@ DO NOT MODIFIY - GENERATED CODE
</dependency>
</dependencies>
<repositories>
<repository>
<id>tb-rubygems-releases</id>
<url>http://rubygems-proxy.torquebox.org/releases</url>
</repository>
<repository>
<id>rubygems-releases</id>
<url>https://otto.takari.io/content/repositories/rubygems/maven/releases</url>
</repository>
<repository>
<id>tb-rubygems-releases</id>
<url>http://rubygems-proxy.torquebox.org/releases</url>
</repository>
</repositories>
<build>
<resources>
16 changes: 1 addition & 15 deletions lib/ruby/stdlib/bigdecimal/math.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'bigdecimal'
require 'bigdecimal/util'

#
#--
@@ -227,19 +226,6 @@ def PI(prec)
#
def E(prec)
raise ArgumentError, "Zero or negative precision for E" if prec <= 0
n = prec + BigDecimal.double_fig
one = BigDecimal("1")
y = one
d = y
z = one
i = 0
while d.nonzero? && ((m = n - (y.exponent - d.exponent).abs) > 0)
m = BigDecimal.double_fig if m < BigDecimal.double_fig
i += 1
z *= i
d = one.div(z,m)
y += d
end
y
BigMath.exp(1, prec)
end
end
2 changes: 1 addition & 1 deletion lib/ruby/stdlib/jruby/compiler.rb
Original file line number Diff line number Diff line change
@@ -125,7 +125,7 @@ def compile_files_with_options(filenames, options = default_options)
# The compilation code
compile_proc = proc do |filename|
begin
file = File.open(filename)
file = File.open(filename, "r:ASCII-8BIT")

if options[:sha1]
pathname = "ruby.jit.FILE_" + Digest::SHA1.hexdigest(File.read(filename)).upcase
22 changes: 1 addition & 21 deletions test/mri/excludes/TestBigDecimal.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,18 @@
exclude :test_exception_overflow, "runs forever"
exclude :test_BigMath_exp, "needs investigation"
exclude :test_BigMath_exp_with_fixnum, "needs investigation"
exclude :test_BigMath_exp_with_float, "needs investigation"
exclude :test_BigMath_exp_with_rational, "needs investigation"

exclude :test_BigMath_exp_under_gc_stress, "needs investigation"
exclude :test_BigMath_log_under_gc_stress, "needs investigation"
exclude :test_dup, "needs investigation"
exclude :test_dup_subclass, "needs investigation"
exclude :test_div, "needs investigation"
exclude :test_exception_underflow, "needs investigation"

exclude :test_exp_with_1, "needs investigation"
exclude :test_exp_with_complex, "needs investigation"
exclude :test_exp_with_nan, "needs investigation"
exclude :test_exp_with_negative_infinite, "needs investigation"
exclude :test_exp_with_negative_precision, "needs investigation"
exclude :test_exp_with_positive_infinite, "needs investigation"
exclude :test_exp_with_zerp_precision, "needs investigation"

exclude :test_global_new, "runs forever"
exclude :test_global_new_with_float, "needs investigation"
exclude :test_limit, "needs investigation"
exclude :test_marshal, "needs investigation"
exclude :test_new, "needs investigation"

exclude :test_power_of_finite_with_zero, "needs investigation"
exclude :test_power_of_nan, "needs investigation"
exclude :test_power_of_negative_infinity, "needs investigation"
exclude :test_power_of_positive_infinity, "needs investigation"
exclude :test_power_of_three, "needs investigation"
exclude :test_power_of_zero, "needs investigation"
exclude :test_power_with_BigDecimal, "needs investigation"
exclude :test_power_with_Bignum, "needs investigation"
exclude :test_power_with_prec, "needs investigation"
exclude :test_power_without_prec, "needs investigation"
@@ -44,6 +26,4 @@
exclude :test_to_special_string, "needs investigation"
exclude :test_zero_p, "needs investigation"
exclude :test_add, "needs investigation"
exclude :test_cmp, "needs investigation"
exclude :test_coerce, "needs investigation"
exclude :test_ctov, "needs investigation"
Original file line number Diff line number Diff line change
@@ -59,16 +59,16 @@ public Object execute(VirtualFrame frame) {

if (startIndex == 0) {
final Object[] arguments = RubyArguments.extractUserArguments(frame.getArguments());
return ArrayNodes.createArray(arrayClass, arguments, length);
return ArrayNodes.createGeneralArray(arrayClass, arguments, length);
} else {
if (startIndex >= endIndex) {
noArgumentsLeftProfile.enter();
return ArrayNodes.createEmptyArray(arrayClass);
return ArrayNodes.createGeneralArray(arrayClass, null, 0);
} else {
subsetOfArgumentsProfile.enter();
final Object[] arguments = RubyArguments.extractUserArguments(frame.getArguments());
// TODO(CS): risk here of widening types too much - always going to be Object[] - does seem to be something that does happen
return ArrayNodes.createArray(arrayClass, ArrayUtils.extractRange(arguments, startIndex, endIndex), length);
return ArrayNodes.createGeneralArray(arrayClass, ArrayUtils.extractRange(arguments, startIndex, endIndex), length);
}
}
}
Original file line number Diff line number Diff line change
@@ -84,7 +84,7 @@ public Object cast(Object nil) {
return createEmptyArray();

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

case NIL:
return nil;
Original file line number Diff line number Diff line change
@@ -41,7 +41,8 @@ protected Object castSingle(Object[] args) {
@TruffleBoundary
@Specialization(guards = { "!noArguments(args)", "!singleArgument(args)" })
protected DynamicObject castMany(Object[] args) {
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), args);
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
return ArrayNodes.createGeneralArray(arrayClass, args, args.length);
}

protected boolean noArguments(Object[] args) {
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ public DynamicObject splat(Object nil) {
return createEmptyArray();

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

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

return ArrayNodes.fromObject(getContext().getCoreLibrary().getArrayClass(), object);
return ArrayNodes.createGeneralArray(getContext().getCoreLibrary().getArrayClass(), new Object[]{object}, 1);
}

}
Original file line number Diff line number Diff line change
@@ -16,10 +16,10 @@
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.ArrayOperations;

public class WhenSplatNode extends RubyNode {

@@ -53,7 +53,7 @@ public boolean executeBoolean(VirtualFrame frame) {
throw new UnsupportedOperationException();
}

for (Object value : ArrayNodes.slowToArray(array)) {
for (Object value : ArrayOperations.toIterable(array)) {
if (dispatchCaseEqual.callBoolean(frame, caseExpression, "===", null, value)) {
return true;
}
Original file line number Diff line number Diff line change
@@ -20,7 +20,6 @@
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.nodes.locals.ReadFrameSlotNode;
import org.jruby.truffle.nodes.locals.ReadFrameSlotNodeGen;
import org.jruby.truffle.nodes.locals.WriteFrameSlotNode;
@@ -29,6 +28,7 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.ThreadLocalObject;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.ArrayOperations;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.truffle.runtime.methods.InternalMethod;

@@ -267,7 +267,7 @@ public DynamicObject localVariables(DynamicObject binding) {
while (frame != null) {
for (Object name : frame.getFrameDescriptor().getIdentifiers()) {
if (name instanceof String) {
ArrayNodes.slowPush(array, getSymbol((String) name));
ArrayOperations.append(array, getSymbol((String) name));
}
}

Original file line number Diff line number Diff line change
@@ -45,7 +45,8 @@ public static DynamicObject asRubyStringArray(DynamicObject exception) {
array[n] = StringNodes.createString(Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(exception)).getContext().getCoreLibrary().getStringClass(), lines.get(n));
}

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

public static void setMessage(DynamicObject exception, Object message) {
30 changes: 18 additions & 12 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
Original file line number Diff line number Diff line change
@@ -62,6 +62,7 @@
import org.jruby.truffle.runtime.backtrace.Activation;
import org.jruby.truffle.runtime.backtrace.Backtrace;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.ArrayOperations;
import org.jruby.truffle.runtime.core.MethodFilter;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.truffle.runtime.methods.InternalMethod;
@@ -1056,7 +1057,7 @@ public DynamicObject instanceVariables(DynamicObject self) {

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

@@ -1200,7 +1201,7 @@ public DynamicObject localVariables() {

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

@@ -1281,8 +1282,9 @@ public DynamicObject methodsRegular(VirtualFrame frame, Object self, boolean reg
final DynamicObject metaClass = metaClassNode.executeMetaClass(frame, self);

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

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

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

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

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

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

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

}
@@ -1756,8 +1761,9 @@ public DynamicObject singletonMethods(VirtualFrame frame, Object self, boolean i
}

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

}
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.array.ArrayUtils;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.ArrayOperations;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.util.ByteList;
import org.jruby.util.CodeRangeable;
@@ -208,7 +209,7 @@ public Object getIndex(DynamicObject matchData, int index, NotProvided length) {
CompilerDirectives.transferToInterpreter();

final Object[] values = Arrays.copyOf(Layouts.MATCH_DATA.getValues(matchData), Layouts.MATCH_DATA.getValues(matchData).length);
final int normalizedIndex = ArrayNodes.normalizeIndex(values.length, index);
final int normalizedIndex = ArrayOperations.normalizeIndex(values.length, index);

if ((normalizedIndex < 0) || (normalizedIndex >= values.length)) {
return nil();
@@ -222,7 +223,7 @@ public Object getIndex(DynamicObject 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 = Arrays.copyOf(Layouts.MATCH_DATA.getValues(matchData), Layouts.MATCH_DATA.getValues(matchData).length);
final int normalizedIndex = ArrayNodes.normalizeIndex(values.length, index);
final int normalizedIndex = ArrayOperations.normalizeIndex(values.length, index);
final Object[] store = Arrays.copyOfRange(values, normalizedIndex, normalizedIndex + length);
return createArray(store, length);
}
@@ -277,9 +278,9 @@ public Object getIndex(VirtualFrame frame, DynamicObject matchData, Object index
@Specialization(guards = "isIntegerFixnumRange(range)")
public Object getIndex(DynamicObject matchData, DynamicObject range, NotProvided len) {
final Object[] values = Arrays.copyOf(Layouts.MATCH_DATA.getValues(matchData), Layouts.MATCH_DATA.getValues(matchData).length);
final int normalizedIndex = ArrayNodes.normalizeIndex(values.length, Layouts.INTEGER_FIXNUM_RANGE.getBegin(range));
final int end = ArrayNodes.normalizeIndex(values.length, Layouts.INTEGER_FIXNUM_RANGE.getEnd(range));
final int exclusiveEnd = ArrayNodes.clampExclusiveIndex(values.length, Layouts.INTEGER_FIXNUM_RANGE.getExcludedEnd(range) ? end : end + 1);
final int normalizedIndex = ArrayOperations.normalizeIndex(values.length, Layouts.INTEGER_FIXNUM_RANGE.getBegin(range));
final int end = ArrayOperations.normalizeIndex(values.length, Layouts.INTEGER_FIXNUM_RANGE.getEnd(range));
final int exclusiveEnd = ArrayOperations.clampExclusiveIndex(values.length, Layouts.INTEGER_FIXNUM_RANGE.getExcludedEnd(range) ? end : end + 1);
final int length = exclusiveEnd - normalizedIndex;

final Object[] store = Arrays.copyOfRange(values, normalizedIndex, normalizedIndex + length);
@@ -325,7 +326,9 @@ public CapturesNode(RubyContext context, SourceSection sourceSection) {
public DynamicObject toA(DynamicObject matchData) {
CompilerDirectives.transferToInterpreter();

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

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

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

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

41 changes: 27 additions & 14 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java
Original file line number Diff line number Diff line change
@@ -50,6 +50,7 @@
import org.jruby.truffle.nodes.yield.YieldDispatchHeadNode;
import org.jruby.truffle.runtime.*;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.ArrayOperations;
import org.jruby.truffle.runtime.core.MethodFilter;
import org.jruby.truffle.runtime.core.ModuleFields;
import org.jruby.truffle.runtime.layouts.Layouts;
@@ -347,7 +348,9 @@ public DynamicObject ancestors(DynamicObject self) {
ancestors.add(module);
}

return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), ancestors.toArray(new Object[ancestors.size()]));
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
Object[] objects = ancestors.toArray(new Object[ancestors.size()]);
return ArrayNodes.createGeneralArray(arrayClass, objects, objects.length);
}
}

@@ -800,10 +803,10 @@ public ClassVariablesNode(RubyContext context, SourceSection sourceSection) {
public DynamicObject getClassVariables(DynamicObject module) {
CompilerDirectives.transferToInterpreter();

final DynamicObject array = ArrayNodes.createEmptyArray(Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(module)).getContext().getCoreLibrary().getArrayClass());
final DynamicObject array = ArrayNodes.createGeneralArray(Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(module)).getContext().getCoreLibrary().getArrayClass(), null, 0);

for (String variable : ModuleOperations.getAllClassVariables(module).keySet()) {
ArrayNodes.slowPush(array, getSymbol(variable));
ArrayOperations.append(array, getSymbol(variable));
}
return array;
}
@@ -844,7 +847,9 @@ public DynamicObject constants(DynamicObject module, boolean inherit) {
}
}

return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), constantsArray.toArray(new Object[constantsArray.size()]));
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
Object[] objects = constantsArray.toArray(new Object[constantsArray.size()]);
return ArrayNodes.createGeneralArray(arrayClass, objects, objects.length);
}

}
@@ -1240,7 +1245,9 @@ public DynamicObject includedModules(DynamicObject module) {
}
}

return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), modules.toArray(new Object[modules.size()]));
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
Object[] objects = modules.toArray(new Object[modules.size()]);
return ArrayNodes.createGeneralArray(arrayClass, objects, objects.length);
}
}

@@ -1347,7 +1354,9 @@ public DynamicObject nesting() {
lexicalScope = lexicalScope.getParent();
}

return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), modules.toArray(new Object[modules.size()]));
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
Object[] objects = modules.toArray(new Object[modules.size()]);
return ArrayNodes.createGeneralArray(arrayClass, objects, objects.length);
}
}

@@ -1502,8 +1511,9 @@ public RubyNode coerceToBoolean(RubyNode includeAncestors) {
@Specialization
public DynamicObject protectedInstanceMethods(DynamicObject module, boolean includeAncestors) {
CompilerDirectives.transferToInterpreter();
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(),
Layouts.MODULE.getFields(module).filterMethods(includeAncestors, MethodFilter.PROTECTED).toArray());
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
Object[] objects = Layouts.MODULE.getFields(module).filterMethods(includeAncestors, MethodFilter.PROTECTED).toArray();
return ArrayNodes.createGeneralArray(arrayClass, objects, objects.length);
}
}

@@ -1551,8 +1561,9 @@ public RubyNode coerceToBoolean(RubyNode includeAncestors) {
public DynamicObject privateInstanceMethods(DynamicObject module, boolean includeAncestors) {
CompilerDirectives.transferToInterpreter();

return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(),
Layouts.MODULE.getFields(module).filterMethods(includeAncestors, MethodFilter.PRIVATE).toArray());
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
Object[] objects = Layouts.MODULE.getFields(module).filterMethods(includeAncestors, MethodFilter.PRIVATE).toArray();
return ArrayNodes.createGeneralArray(arrayClass, objects, objects.length);
}
}

@@ -1610,8 +1621,9 @@ public RubyNode coerceToBoolean(RubyNode includeAncestors) {
public DynamicObject publicInstanceMethods(DynamicObject module, boolean includeAncestors) {
CompilerDirectives.transferToInterpreter();

return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(),
Layouts.MODULE.getFields(module).filterMethods(includeAncestors, MethodFilter.PUBLIC).toArray());
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
Object[] objects = Layouts.MODULE.getFields(module).filterMethods(includeAncestors, MethodFilter.PUBLIC).toArray();
return ArrayNodes.createGeneralArray(arrayClass, objects, objects.length);
}
}

@@ -1659,8 +1671,9 @@ public RubyNode coerceToBoolean(RubyNode includeAncestors) {
public DynamicObject instanceMethods(DynamicObject module, boolean includeAncestors) {
CompilerDirectives.transferToInterpreter();

return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(),
Layouts.MODULE.getFields(module).filterMethods(includeAncestors, MethodFilter.PUBLIC_PROTECTED).toArray());
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
Object[] objects = Layouts.MODULE.getFields(module).filterMethods(includeAncestors, MethodFilter.PUBLIC_PROTECTED).toArray();
return ArrayNodes.createGeneralArray(arrayClass, objects, objects.length);
}
}

Original file line number Diff line number Diff line change
@@ -155,7 +155,9 @@ public DefineFinalizerNode(RubyContext context, SourceSection sourceSection) {
public DynamicObject defineFinalizer(VirtualFrame frame, Object object, Object finalizer) {
if (respondToNode.executeBoolean(frame, finalizer)) {
registerFinalizer(object, finalizer);
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), 0, finalizer);
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
Object[] objects = new Object[]{0, finalizer};
return ArrayNodes.createGeneralArray(arrayClass, objects, objects.length);
} else {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentErrorWrongArgumentType(finalizer, "callable", this));
Original file line number Diff line number Diff line change
@@ -269,8 +269,9 @@ public Object sourceLocation(DynamicObject proc) {
return nil();
} else {
DynamicObject file = createString(sourceSection.getSource().getName());
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(),
file, sourceSection.getStartLine());
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
Object[] objects = new Object[]{file, sourceSection.getStartLine()};
return ArrayNodes.createGeneralArray(arrayClass, objects, objects.length);
}
}

Original file line number Diff line number Diff line change
@@ -661,7 +661,7 @@ public Object rubiniusNames(VirtualFrame frame, DynamicObject regexp) {
final DynamicObject name = getSymbol(new ByteList(e.name, e.nameP, e.nameEnd - e.nameP, false));

final int[] backrefs = e.getBackRefs();
final DynamicObject backrefsRubyArray = ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(), backrefs, backrefs.length);
final DynamicObject backrefsRubyArray = ArrayNodes.createGeneralArray(getContext().getCoreLibrary().getArrayClass(), backrefs, backrefs.length);

lookupTableWriteNode.call(frame, namesLookupTable, "[]=", null, name, backrefsRubyArray);
}
Original file line number Diff line number Diff line change
@@ -52,7 +52,6 @@
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.FixnumLowerNodeGen;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
@@ -64,6 +63,7 @@
import org.jruby.truffle.runtime.NotProvided;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.ArrayOperations;
import org.jruby.truffle.runtime.core.StringCodeRangeableWrapper;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.util.*;
@@ -176,7 +176,7 @@ public static int length(DynamicObject string) {
}

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

public static int normalizeIndex(DynamicObject rubyString, int index) {
@@ -185,7 +185,7 @@ public static int normalizeIndex(DynamicObject rubyString, int index) {

public static int clampExclusiveIndex(DynamicObject string, int index) {
assert RubyGuards.isRubyString(string);
return ArrayNodes.clampExclusiveIndex(Layouts.STRING.getByteList(string).length(), index);
return ArrayOperations.clampExclusiveIndex(Layouts.STRING.getByteList(string).length(), index);
}

@TruffleBoundary
Original file line number Diff line number Diff line change
@@ -23,16 +23,15 @@
import org.jruby.RubyGC;
import org.jruby.ext.rbconfig.RbConfigLibrary;
import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyCallStack;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.backtrace.Backtrace;
import org.jruby.truffle.runtime.backtrace.BacktraceFormatter;
import org.jruby.truffle.runtime.backtrace.BacktraceInterleaver;
import org.jruby.truffle.runtime.cext.CExtManager;
import org.jruby.truffle.runtime.cext.CExtSubsystem;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.ArrayOperations;
import org.jruby.truffle.runtime.core.CoreLibrary;
import org.jruby.truffle.runtime.hash.BucketsStrategy;
import org.jruby.truffle.runtime.layouts.Layouts;
@@ -391,7 +390,7 @@ private String[] toStrings(DynamicObject array) {

int n = 0;

for (Object object : ArrayNodes.slowToArray(array)) {
for (Object object : ArrayOperations.toIterable(array)) {
if (RubyGuards.isRubyString(object) || RubyGuards.isRubySymbol(object)) {
strings[n] = object.toString();
n++;
Original file line number Diff line number Diff line change
@@ -187,8 +187,9 @@ public Object sourceLocation(DynamicObject unboundMethod) {
return nil();
} else {
DynamicObject file = createString(sourceSection.getSource().getName());
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(),
file, sourceSection.getStartLine());
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
Object[] objects = new Object[]{file, sourceSection.getStartLine()};
return ArrayNodes.createGeneralArray(arrayClass, objects, objects.length);
}
}

Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.array.ArrayMirror;
import org.jruby.truffle.runtime.array.ArrayReflector;
import org.jruby.truffle.runtime.array.ArrayUtils;
import org.jruby.truffle.runtime.layouts.Layouts;

@@ -41,25 +42,29 @@ public AppendManyNode(RubyContext context, SourceSection sourceSection) {

@Specialization(guards = {"isRubyArray(array)", "isEmptyArray(array)"})
public DynamicObject appendManyEmpty(DynamicObject array, int otherSize, int[] other) {
ArrayNodes.setStore(array, Arrays.copyOf(other, otherSize), otherSize);
Layouts.ARRAY.setStore(array, Arrays.copyOf(other, otherSize));
Layouts.ARRAY.setSize(array, otherSize);
return array;
}

@Specialization(guards = {"isRubyArray(array)", "isEmptyArray(array)"})
public DynamicObject appendManyEmpty(DynamicObject array, int otherSize, long[] other) {
ArrayNodes.setStore(array, Arrays.copyOf(other, otherSize), otherSize);
Layouts.ARRAY.setStore(array, Arrays.copyOf(other, otherSize));
Layouts.ARRAY.setSize(array, otherSize);
return array;
}

@Specialization(guards = {"isRubyArray(array)", "isEmptyArray(array)"})
public DynamicObject appendManyEmpty(DynamicObject array, int otherSize, double[] other) {
ArrayNodes.setStore(array, Arrays.copyOf(other, otherSize), otherSize);
Layouts.ARRAY.setStore(array, Arrays.copyOf(other, otherSize));
Layouts.ARRAY.setSize(array, otherSize);
return array;
}

@Specialization(guards = {"isRubyArray(array)", "isEmptyArray(array)"})
public DynamicObject appendManyEmpty(DynamicObject array, int otherSize, Object[] other) {
ArrayNodes.setStore(array, Arrays.copyOf(other, otherSize), otherSize);
Layouts.ARRAY.setStore(array, Arrays.copyOf(other, otherSize));
Layouts.ARRAY.setSize(array, otherSize);
return array;
}

@@ -68,32 +73,32 @@ public DynamicObject appendManyEmpty(DynamicObject array, int otherSize, Object[
@Specialization(guards = {"isRubyArray(array)", "isIntArray(array)"})
public DynamicObject appendManySameType(DynamicObject array, int otherSize, int[] other,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendManySameTypeGeneric(array, ArrayMirror.reflect((int[]) Layouts.ARRAY.getStore(array)),
otherSize, ArrayMirror.reflect(other), extendProfile);
appendManySameTypeGeneric(array, ArrayReflector.reflect((int[]) Layouts.ARRAY.getStore(array)),
otherSize, ArrayReflector.reflect(other), extendProfile);
return array;
}

@Specialization(guards = {"isRubyArray(array)", "isLongArray(array)"})
public DynamicObject appendManySameType(DynamicObject array, int otherSize, long[] other,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendManySameTypeGeneric(array, ArrayMirror.reflect((long[]) Layouts.ARRAY.getStore(array)),
otherSize, ArrayMirror.reflect(other), extendProfile);
appendManySameTypeGeneric(array, ArrayReflector.reflect((long[]) Layouts.ARRAY.getStore(array)),
otherSize, ArrayReflector.reflect(other), extendProfile);
return array;
}

@Specialization(guards = {"isRubyArray(array)", "isDoubleArray(array)"})
public DynamicObject appendManySameType(DynamicObject array, int otherSize, double[] other,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendManySameTypeGeneric(array, ArrayMirror.reflect((double[]) Layouts.ARRAY.getStore(array)),
otherSize, ArrayMirror.reflect(other), extendProfile);
appendManySameTypeGeneric(array, ArrayReflector.reflect((double[]) Layouts.ARRAY.getStore(array)),
otherSize, ArrayReflector.reflect(other), extendProfile);
return array;
}

@Specialization(guards = {"isRubyArray(array)", "isObjectArray(array)"})
public DynamicObject appendManySameType(DynamicObject array, int otherSize, Object[] other,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendManySameTypeGeneric(array, ArrayMirror.reflect((Object[]) Layouts.ARRAY.getStore(array)),
otherSize, ArrayMirror.reflect(other), extendProfile);
appendManySameTypeGeneric(array, ArrayReflector.reflect((Object[]) Layouts.ARRAY.getStore(array)),
otherSize, ArrayReflector.reflect(other), extendProfile);
return array;
}

@@ -112,29 +117,30 @@ public void appendManySameTypeGeneric(DynamicObject array, ArrayMirror storeMirr
}

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

// Append something else into an Object[]

@Specialization(guards = {"isRubyArray(array)", "isObjectArray(array)"})
public DynamicObject appendManyBoxIntoObject(DynamicObject array, int otherSize, int[] other,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendManyBoxIntoObjectGeneric(array, otherSize, ArrayMirror.reflect(other), extendProfile);
appendManyBoxIntoObjectGeneric(array, otherSize, ArrayReflector.reflect(other), extendProfile);
return array;
}

@Specialization(guards = {"isRubyArray(array)", "isObjectArray(array)"})
public DynamicObject appendManyBoxIntoObject(DynamicObject array, int otherSize, long[] other,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendManyBoxIntoObjectGeneric(array, otherSize, ArrayMirror.reflect(other), extendProfile);
appendManyBoxIntoObjectGeneric(array, otherSize, ArrayReflector.reflect(other), extendProfile);
return array;
}

@Specialization(guards = {"isRubyArray(array)", "isObjectArray(array)"})
public DynamicObject appendManyBoxIntoObject(DynamicObject array, int otherSize, double[] other,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendManyBoxIntoObjectGeneric(array, otherSize, ArrayMirror.reflect(other), extendProfile);
appendManyBoxIntoObjectGeneric(array, otherSize, ArrayReflector.reflect(other), extendProfile);
return array;
}

@@ -153,7 +159,8 @@ public void appendManyBoxIntoObjectGeneric(DynamicObject array, int otherSize, A
}

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

// Append forcing a generalization from int[] to long[]
@@ -168,58 +175,59 @@ public DynamicObject appendManyLongIntoInteger(DynamicObject array, int otherSiz

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

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

// Append forcing a generalization to Object[]

@Specialization(guards = {"isRubyArray(array)", "isIntArray(array)"})
public DynamicObject appendManyGeneralizeIntegerDouble(DynamicObject array, int otherSize, double[] other) {
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((int[]) Layouts.ARRAY.getStore(array)),
otherSize, ArrayMirror.reflect(other));
appendManyGeneralizeGeneric(array, ArrayReflector.reflect((int[]) Layouts.ARRAY.getStore(array)),
otherSize, ArrayReflector.reflect(other));
return array;
}

@Specialization(guards = {"isRubyArray(array)", "isIntArray(array)"})
public DynamicObject appendManyGeneralizeIntegerDouble(DynamicObject array, int otherSize, Object[] other) {
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((int[]) Layouts.ARRAY.getStore(array)),
otherSize, ArrayMirror.reflect(other));
appendManyGeneralizeGeneric(array, ArrayReflector.reflect((int[]) Layouts.ARRAY.getStore(array)),
otherSize, ArrayReflector.reflect(other));
return array;
}

@Specialization(guards = {"isRubyArray(array)", "isLongArray(array)"})
public DynamicObject appendManyGeneralizeLongDouble(DynamicObject array, int otherSize, double[] other) {
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((long[]) Layouts.ARRAY.getStore(array)),
otherSize, ArrayMirror.reflect(other));
appendManyGeneralizeGeneric(array, ArrayReflector.reflect((long[]) Layouts.ARRAY.getStore(array)),
otherSize, ArrayReflector.reflect(other));
return array;
}

@Specialization(guards = {"isRubyArray(array)", "isLongArray(array)"})
public DynamicObject appendManyGeneralizeLongDouble(DynamicObject array, int otherSize, Object[] other) {
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((long[]) Layouts.ARRAY.getStore(array)),
otherSize, ArrayMirror.reflect(other));
appendManyGeneralizeGeneric(array, ArrayReflector.reflect((long[]) Layouts.ARRAY.getStore(array)),
otherSize, ArrayReflector.reflect(other));
return array;
}

@Specialization(guards = {"isRubyArray(array)", "isDoubleArray(array)"})
public DynamicObject appendManyGeneralizeDoubleInteger(DynamicObject array, int otherSize, int[] other) {
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((double[]) Layouts.ARRAY.getStore(array)),
otherSize, ArrayMirror.reflect(other));
appendManyGeneralizeGeneric(array, ArrayReflector.reflect((double[]) Layouts.ARRAY.getStore(array)),
otherSize, ArrayReflector.reflect(other));
return array;
}

@Specialization(guards = {"isRubyArray(array)", "isDoubleArray(array)"})
public DynamicObject appendManyGeneralizeDoubleLong(DynamicObject array, int otherSize, long[] other) {
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((double[]) Layouts.ARRAY.getStore(array)),
otherSize, ArrayMirror.reflect(other));
appendManyGeneralizeGeneric(array, ArrayReflector.reflect((double[]) Layouts.ARRAY.getStore(array)),
otherSize, ArrayReflector.reflect(other));
return array;
}

@Specialization(guards = {"isRubyArray(array)", "isDoubleArray(array)"})
public DynamicObject appendManyGeneralizeDoubleObject(DynamicObject array, int otherSize, Object[] other) {
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((double[]) Layouts.ARRAY.getStore(array)),
otherSize, ArrayMirror.reflect(other));
appendManyGeneralizeGeneric(array, ArrayReflector.reflect((double[]) Layouts.ARRAY.getStore(array)),
otherSize, ArrayReflector.reflect(other));
return array;
}

@@ -228,7 +236,8 @@ public void appendManyGeneralizeGeneric(DynamicObject array, ArrayMirror storeMi
final int newSize = oldSize + otherSize;
Object[] newStore = storeMirror.getBoxedCopy(ArrayUtils.capacity(storeMirror.getLength(), newSize));
otherStoreMirror.copyTo(newStore, 0, oldSize, otherSize);
ArrayNodes.setStore(array, newStore, newSize);
Layouts.ARRAY.setStore(array, newStore);
Layouts.ARRAY.setSize(array, newSize);
}

}
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.array.ArrayMirror;
import org.jruby.truffle.runtime.array.ArrayReflector;
import org.jruby.truffle.runtime.array.ArrayUtils;
import org.jruby.truffle.runtime.layouts.Layouts;

@@ -38,25 +39,29 @@ public AppendOneNode(RubyContext context, SourceSection sourceSection) {

@Specialization(guards = {"isRubyArray(array)", "isEmptyArray(array)"})
public DynamicObject appendOneEmpty(DynamicObject array, int value) {
ArrayNodes.setStore(array, new int[]{value}, 1);
Layouts.ARRAY.setStore(array, new int[]{value});
Layouts.ARRAY.setSize(array, 1);
return array;
}

@Specialization(guards = {"isRubyArray(array)", "isEmptyArray(array)"})
public DynamicObject appendOneEmpty(DynamicObject array, long value) {
ArrayNodes.setStore(array, new long[]{value}, 1);
Layouts.ARRAY.setStore(array, new long[]{value});
Layouts.ARRAY.setSize(array, 1);
return array;
}

@Specialization(guards = {"isRubyArray(array)", "isEmptyArray(array)"})
public DynamicObject appendOneEmpty(DynamicObject array, double value) {
ArrayNodes.setStore(array, new double[]{value}, 1);
Layouts.ARRAY.setStore(array, new double[]{value});
Layouts.ARRAY.setSize(array, 1);
return array;
}

@Specialization(guards = {"isRubyArray(array)", "isEmptyArray(array)"})
public DynamicObject appendOneEmpty(DynamicObject array, Object value) {
ArrayNodes.setStore(array, new Object[]{value}, 1);
Layouts.ARRAY.setStore(array, new Object[]{value});
Layouts.ARRAY.setSize(array, 1);
return array;
}

@@ -65,28 +70,28 @@ public DynamicObject appendOneEmpty(DynamicObject array, Object value) {
@Specialization(guards = {"isRubyArray(array)", "isIntArray(array)"})
public DynamicObject appendOneSameType(DynamicObject array, int value,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendOneSameTypeGeneric(array, ArrayMirror.reflect((int[]) Layouts.ARRAY.getStore(array)), value, extendProfile);
appendOneSameTypeGeneric(array, ArrayReflector.reflect((int[]) Layouts.ARRAY.getStore(array)), value, extendProfile);
return array;
}

@Specialization(guards = {"isRubyArray(array)", "isLongArray(array)"})
public DynamicObject appendOneSameType(DynamicObject array, long value,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendOneSameTypeGeneric(array, ArrayMirror.reflect((long[]) Layouts.ARRAY.getStore(array)), value, extendProfile);
appendOneSameTypeGeneric(array, ArrayReflector.reflect((long[]) Layouts.ARRAY.getStore(array)), value, extendProfile);
return array;
}

@Specialization(guards = {"isRubyArray(array)", "isDoubleArray(array)"})
public DynamicObject appendOneSameType(DynamicObject array, double value,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendOneSameTypeGeneric(array, ArrayMirror.reflect((double[]) Layouts.ARRAY.getStore(array)), value, extendProfile);
appendOneSameTypeGeneric(array, ArrayReflector.reflect((double[]) Layouts.ARRAY.getStore(array)), value, extendProfile);
return array;
}

@Specialization(guards = {"isRubyArray(array)", "isObjectArray(array)"})
public DynamicObject appendOneSameType(DynamicObject array, Object value,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendOneSameTypeGeneric(array, ArrayMirror.reflect((Object[]) Layouts.ARRAY.getStore(array)), value, extendProfile);
appendOneSameTypeGeneric(array, ArrayReflector.reflect((Object[]) Layouts.ARRAY.getStore(array)), value, extendProfile);
return array;
}

@@ -103,7 +108,8 @@ public void appendOneSameTypeGeneric(DynamicObject array, ArrayMirror storeMirro
}

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

// Append forcing a generalization from int[] to long[]
@@ -117,27 +123,28 @@ public DynamicObject appendOneLongIntoInteger(DynamicObject array, long value) {
long[] newStore = ArrayUtils.longCopyOf(oldStore, ArrayUtils.capacity(oldStore.length, newSize));

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

// Append forcing a generalization to Object[]

@Specialization(guards = {"isRubyArray(array)", "isIntArray(array)", "!isInteger(value)", "!isLong(value)"})
public DynamicObject appendOneGeneralizeInteger(DynamicObject array, Object value) {
appendOneGeneralizeGeneric(array, ArrayMirror.reflect((int[]) Layouts.ARRAY.getStore(array)), value);
appendOneGeneralizeGeneric(array, ArrayReflector.reflect((int[]) Layouts.ARRAY.getStore(array)), value);
return array;
}

@Specialization(guards = {"isRubyArray(array)", "isLongArray(array)", "!isInteger(value)", "!isLong(value)"})
public DynamicObject appendOneGeneralizeLong(DynamicObject array, Object value) {
appendOneGeneralizeGeneric(array, ArrayMirror.reflect((long[]) Layouts.ARRAY.getStore(array)), value);
appendOneGeneralizeGeneric(array, ArrayReflector.reflect((long[]) Layouts.ARRAY.getStore(array)), value);
return array;
}

@Specialization(guards = {"isRubyArray(array)", "isDoubleArray(array)", "!isDouble(value)"})
public DynamicObject appendOneGeneralizeDouble(DynamicObject array, Object value) {
appendOneGeneralizeGeneric(array, ArrayMirror.reflect((double[]) Layouts.ARRAY.getStore(array)), value);
appendOneGeneralizeGeneric(array, ArrayReflector.reflect((double[]) Layouts.ARRAY.getStore(array)), value);
return array;
}

@@ -146,7 +153,8 @@ public void appendOneGeneralizeGeneric(DynamicObject array, ArrayMirror storeMir
final int newSize = oldSize + 1;
Object[] newStore = storeMirror.getBoxedCopy(ArrayUtils.capacity(storeMirror.getLength(), newSize));
newStore[oldSize] = value;
ArrayNodes.setStore(array, newStore, newSize);
Layouts.ARRAY.setStore(array, newStore);
Layouts.ARRAY.setSize(array, newSize);
}

}
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
import com.oracle.truffle.api.utilities.ConditionProfile;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.array.ArrayUtils;
import org.jruby.truffle.runtime.core.ArrayOperations;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.util.cli.Options;

@@ -89,7 +90,7 @@ public Object ensure(Object store, int length) {
public Object appendArray(Object store, int index, DynamicObject array) {
CompilerDirectives.transferToInterpreter();

for (Object value : ArrayNodes.slowToArray(array)) {
for (Object value : ArrayOperations.toIterable(array)) {
store = appendValue(store, index, value);
index++;
}
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
import org.jruby.truffle.nodes.objects.AllocateObjectNode;
import org.jruby.truffle.nodes.objects.AllocateObjectNodeGen;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.CoreLibrary;
import org.jruby.truffle.runtime.layouts.Layouts;

import java.util.Arrays;
@@ -50,7 +51,8 @@ protected DynamicObject makeGeneric(VirtualFrame frame, Object[] alreadyExecuted
}
}

return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), executedValues);
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
return ArrayNodes.createGeneralArray(arrayClass, executedValues, executedValues.length);
}

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

final DynamicObject array = ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), executedValues);
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
final DynamicObject array = ArrayNodes.createGeneralArray(arrayClass, storeSpecialisedFromObjects(executedValues), executedValues.length);
final Object store = Layouts.ARRAY.getStore(array);

if (store == null) {
@@ -254,5 +257,73 @@ public Object execute(VirtualFrame frame) {
return array;
}

public Object storeSpecialisedFromObjects(Object... objects) {
if (objects.length == 0) {
return null;
}

boolean canUseInteger = true;
boolean canUseLong = true;
boolean canUseDouble = true;

for (Object object : objects) {
if (object instanceof Integer) {
canUseDouble = false;
} else if (object instanceof Long) {
canUseInteger = canUseInteger && CoreLibrary.fitsIntoInteger((long) object);
canUseDouble = false;
} else if (object instanceof Double) {
canUseInteger = false;
canUseLong = false;
} else {
canUseInteger = false;
canUseLong = false;
canUseDouble = false;
}
}

if (canUseInteger) {
final int[] store = new int[objects.length];

for (int n = 0; n < objects.length; n++) {
final Object object = objects[n];
if (object instanceof Integer) {
store[n] = (int) object;
} else if (object instanceof Long) {
store[n] = (int) (long) object;
} else {
throw new UnsupportedOperationException();
}
}

return store;
} else if (canUseLong) {
final long[] store = new long[objects.length];

for (int n = 0; n < objects.length; n++) {
final Object object = objects[n];
if (object instanceof Integer) {
store[n] = (long) (int) object;
} else if (object instanceof Long) {
store[n] = (long) object;
} else {
throw new UnsupportedOperationException();
}
}

return store;
} else if (canUseDouble) {
final double[] store = new double[objects.length];

for (int n = 0; n < objects.length; n++) {
store[n] = CoreLibrary.toDouble(objects[n], getContext().getCoreLibrary().getNilObject());
}

return store;
} else {
return objects;
}
}

}
}
639 changes: 247 additions & 392 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayNodes.java

Large diffs are not rendered by default.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -18,6 +18,8 @@
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.ArrayOperations;
import org.jruby.truffle.runtime.layouts.Layouts;

@NodeChildren({
@NodeChild(value="array", type=RubyNode.class),
@@ -40,7 +42,7 @@ public Object read(VirtualFrame frame, DynamicObject array, int index) {
readNode = insert(ArrayReadNormalizedNodeGen.create(getContext(), getSourceSection(), null, null));
}

final int normalizedIndex = ArrayNodes.normalizeIndex(array, index);
final int normalizedIndex = ArrayOperations.normalizeIndex(Layouts.ARRAY.getSize(array), index);

return readNode.executeRead(frame, array, normalizedIndex);
}
Original file line number Diff line number Diff line change
@@ -18,6 +18,8 @@
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.ArrayOperations;
import org.jruby.truffle.runtime.layouts.Layouts;

@NodeChildren({
@NodeChild(value="array", type=RubyNode.class),
@@ -41,7 +43,7 @@ public Object read(VirtualFrame frame, DynamicObject array, int index, int lengt
readNode = insert(ArrayReadSliceNormalizedNodeGen.create(getContext(), getSourceSection(), null, null, null));
}

final int normalizedIndex = ArrayNodes.normalizeIndex(array, index);
final int normalizedIndex = ArrayOperations.normalizeIndex(Layouts.ARRAY.getSize(array), index);

return readNode.executeReadSlice(frame, array, normalizedIndex, length);
}
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ public DynamicObject readNegativeLength(DynamicObject array, int index, int leng
guards={"isRubyArray(array)", "indexInBounds(array, index)", "lengthPositive(length)", "isNullArray(array)"}
)
public DynamicObject readNull(DynamicObject array, int index, int length) {
return ArrayNodes.createEmptyArray(Layouts.BASIC_OBJECT.getLogicalClass(array));
return ArrayNodes.createGeneralArray(Layouts.BASIC_OBJECT.getLogicalClass(array), null, 0);
}

// Reading within bounds on an array with actual storage
@@ -67,32 +67,28 @@ public DynamicObject readNull(DynamicObject array, int index, int length) {
guards={"isRubyArray(array)", "indexInBounds(array, index)", "lengthPositive(length)", "endInBounds(array, index, length)", "isIntArray(array)"}
)
public DynamicObject readIntInBounds(DynamicObject array, int index, int length) {
return ArrayNodes.createArray(Layouts.BASIC_OBJECT.getLogicalClass(array),
Arrays.copyOfRange((int[]) Layouts.ARRAY.getStore(array), index, index + length), length);
return ArrayNodes.createGeneralArray(Layouts.BASIC_OBJECT.getLogicalClass(array), Arrays.copyOfRange((int[]) Layouts.ARRAY.getStore(array), index, index + length), length);
}

@Specialization(
guards={"isRubyArray(array)", "indexInBounds(array, index)", "lengthPositive(length)", "endInBounds(array, index, length)", "isLongArray(array)"}
)
public DynamicObject readLongInBounds(DynamicObject array, int index, int length) {
return ArrayNodes.createArray(Layouts.BASIC_OBJECT.getLogicalClass(array),
Arrays.copyOfRange((long[]) Layouts.ARRAY.getStore(array), index, index + length), length);
return ArrayNodes.createGeneralArray(Layouts.BASIC_OBJECT.getLogicalClass(array), Arrays.copyOfRange((long[]) Layouts.ARRAY.getStore(array), index, index + length), length);
}

@Specialization(
guards={"isRubyArray(array)", "indexInBounds(array, index)", "lengthPositive(length)", "endInBounds(array, index, length)", "isDoubleArray(array)"}
)
public DynamicObject readDoubleInBounds(DynamicObject array, int index, int length) {
return ArrayNodes.createArray(Layouts.BASIC_OBJECT.getLogicalClass(array),
Arrays.copyOfRange((double[]) Layouts.ARRAY.getStore(array), index, index + length), length);
return ArrayNodes.createGeneralArray(Layouts.BASIC_OBJECT.getLogicalClass(array), Arrays.copyOfRange((double[]) Layouts.ARRAY.getStore(array), index, index + length), length);
}

@Specialization(
guards={"isRubyArray(array)", "indexInBounds(array, index)", "lengthPositive(length)", "endInBounds(array, index, length)", "isObjectArray(array)"}
)
public DynamicObject readObjectInBounds(DynamicObject array, int index, int length) {
return ArrayNodes.createArray(Layouts.BASIC_OBJECT.getLogicalClass(array),
Arrays.copyOfRange((Object[]) Layouts.ARRAY.getStore(array), index, index + length), length);
return ArrayNodes.createGeneralArray(Layouts.BASIC_OBJECT.getLogicalClass(array), Arrays.copyOfRange((Object[]) Layouts.ARRAY.getStore(array), index, index + length), length);
}

// Reading beyond upper bounds on an array with actual storage needs clamping
@@ -103,8 +99,7 @@ public DynamicObject readObjectInBounds(DynamicObject array, int index, int leng
public DynamicObject readIntOutOfBounds(DynamicObject array, int index, int length) {
final int clampedLength = Math.min(Layouts.ARRAY.getSize(array), index + length) - index;

return ArrayNodes.createArray(Layouts.BASIC_OBJECT.getLogicalClass(array),
Arrays.copyOfRange((int[]) Layouts.ARRAY.getStore(array), index, index + clampedLength), clampedLength);
return ArrayNodes.createGeneralArray(Layouts.BASIC_OBJECT.getLogicalClass(array), Arrays.copyOfRange((int[]) Layouts.ARRAY.getStore(array), index, index + clampedLength), clampedLength);
}

@Specialization(
@@ -113,8 +108,7 @@ public DynamicObject readIntOutOfBounds(DynamicObject array, int index, int leng
public DynamicObject readLongOutOfBounds(DynamicObject array, int index, int length) {
final int clampedLength = Math.min(Layouts.ARRAY.getSize(array), index + length) - index;

return ArrayNodes.createArray(Layouts.BASIC_OBJECT.getLogicalClass(array),
Arrays.copyOfRange((long[]) Layouts.ARRAY.getStore(array), index, index + clampedLength), clampedLength);
return ArrayNodes.createGeneralArray(Layouts.BASIC_OBJECT.getLogicalClass(array), Arrays.copyOfRange((long[]) Layouts.ARRAY.getStore(array), index, index + clampedLength), clampedLength);
}

@Specialization(
@@ -123,8 +117,7 @@ public DynamicObject readLongOutOfBounds(DynamicObject array, int index, int len
public DynamicObject readDoubleOutOfBounds(DynamicObject array, int index, int length) {
final int clampedLength = Math.min(Layouts.ARRAY.getSize(array), index + length) - index;

return ArrayNodes.createArray(Layouts.BASIC_OBJECT.getLogicalClass(array),
Arrays.copyOfRange((double[]) Layouts.ARRAY.getStore(array), index, index + clampedLength), clampedLength);
return ArrayNodes.createGeneralArray(Layouts.BASIC_OBJECT.getLogicalClass(array), Arrays.copyOfRange((double[]) Layouts.ARRAY.getStore(array), index, index + clampedLength), clampedLength);
}

@Specialization(
@@ -133,8 +126,7 @@ public DynamicObject readDoubleOutOfBounds(DynamicObject array, int index, int l
public DynamicObject readObjectOutOfBounds(DynamicObject array, int index, int length) {
final int clampedLength = Math.min(Layouts.ARRAY.getSize(array), index + length) - index;

return ArrayNodes.createArray(Layouts.BASIC_OBJECT.getLogicalClass(array),
Arrays.copyOfRange((Object[]) Layouts.ARRAY.getStore(array), index, index + clampedLength), clampedLength);
return ArrayNodes.createGeneralArray(Layouts.BASIC_OBJECT.getLogicalClass(array), Arrays.copyOfRange((Object[]) Layouts.ARRAY.getStore(array), index, index + clampedLength), clampedLength);
}

// Guards
Original file line number Diff line number Diff line change
@@ -18,6 +18,8 @@
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.ArrayOperations;
import org.jruby.truffle.runtime.layouts.Layouts;

@NodeChildren({
@NodeChild(value="array", type=RubyNode.class),
@@ -41,7 +43,7 @@ public Object write(VirtualFrame frame, DynamicObject array, int index, Object v
writeNode = insert(ArrayWriteNormalizedNodeGen.create(getContext(), getSourceSection(), null, null, null));
}

final int normalizedIndex = ArrayNodes.normalizeIndex(array, index);
final int normalizedIndex = ArrayOperations.normalizeIndex(Layouts.ARRAY.getSize(array), index);

return writeNode.executeWrite(frame, array, normalizedIndex, value);
}
Original file line number Diff line number Diff line change
@@ -48,39 +48,44 @@ public ArrayWriteNormalizedNode(RubyContext context, SourceSection sourceSection
guards={"isRubyArray(array)", "isNullArray(array)", "index == 0"}
)
public boolean writeNull0(DynamicObject array, int index, boolean value) {
ArrayNodes.setStore(array, new Object[]{value}, 1);
Layouts.ARRAY.setStore(array, new Object[]{value});
Layouts.ARRAY.setSize(array, 1);
return value;
}

@Specialization(
guards={"isRubyArray(array)", "isNullArray(array)", "index == 0"}
)
public int writeNull0(DynamicObject array, int index, int value) {
ArrayNodes.setStore(array, new int[]{value}, 1);
Layouts.ARRAY.setStore(array, new int[]{value});
Layouts.ARRAY.setSize(array, 1);
return value;
}

@Specialization(
guards={"isRubyArray(array)", "isNullArray(array)", "index == 0"}
)
public long writeNull0(DynamicObject array, int index, long value) {
ArrayNodes.setStore(array, new long[]{value}, 1);
Layouts.ARRAY.setStore(array, new long[]{value});
Layouts.ARRAY.setSize(array, 1);
return value;
}

@Specialization(
guards={"isRubyArray(array)", "isNullArray(array)", "index == 0"}
)
public double writeNull0(DynamicObject array, int index, double value) {
ArrayNodes.setStore(array, new double[]{value}, 1);
Layouts.ARRAY.setStore(array, new double[]{value});
Layouts.ARRAY.setSize(array, 1);
return value;
}

@Specialization(
guards={"isRubyArray(array)", "isNullArray(array)", "index == 0"}
)
public DynamicObject writeNull0(DynamicObject array, int index, DynamicObject value) {
ArrayNodes.setStore(array, new Object[]{value}, 1);
Layouts.ARRAY.setStore(array, new Object[]{value});
Layouts.ARRAY.setSize(array, 1);
return value;
}

@@ -97,7 +102,8 @@ public Object writeNullBeyond(DynamicObject array, int index, Object value) {
}

store[index] = value;
ArrayNodes.setStore(array, store, store.length);
Layouts.ARRAY.setStore(array, store);
Layouts.ARRAY.setSize(array, store.length);
return value;
}

@@ -170,7 +176,8 @@ public long writeWithinInt(DynamicObject array, int index, long value) {
}

longStore[index] = value;
ArrayNodes.setStore(array, longStore, Layouts.ARRAY.getSize(array));
Layouts.ARRAY.setStore(array, longStore);
Layouts.ARRAY.setSize(array, Layouts.ARRAY.getSize(array));
return value;
}

@@ -180,7 +187,8 @@ public long writeWithinInt(DynamicObject array, int index, long value) {
public Object writeWithinInt(DynamicObject array, int index, Object value) {
final Object[] objectStore = ArrayUtils.box((int[]) Layouts.ARRAY.getStore(array));
objectStore[index] = value;
ArrayNodes.setStore(array, objectStore, Layouts.ARRAY.getSize(array));
Layouts.ARRAY.setStore(array, objectStore);
Layouts.ARRAY.setSize(array, Layouts.ARRAY.getSize(array));
return value;
}

@@ -190,7 +198,8 @@ public Object writeWithinInt(DynamicObject array, int index, Object value) {
public Object writeWithinLong(DynamicObject array, int index, Object value) {
final Object[] objectStore = ArrayUtils.box((long[]) Layouts.ARRAY.getStore(array));
objectStore[index] = value;
ArrayNodes.setStore(array, objectStore, Layouts.ARRAY.getSize(array));
Layouts.ARRAY.setStore(array, objectStore);
Layouts.ARRAY.setSize(array, Layouts.ARRAY.getSize(array));
return value;
}

@@ -200,7 +209,8 @@ public Object writeWithinLong(DynamicObject array, int index, Object value) {
public Object writeWithinDouble(DynamicObject array, int index, Object value) {
final Object[] objectStore = ArrayUtils.box((double[]) Layouts.ARRAY.getStore(array));
objectStore[index] = value;
ArrayNodes.setStore(array, objectStore, Layouts.ARRAY.getSize(array));
Layouts.ARRAY.setStore(array, objectStore);
Layouts.ARRAY.setSize(array, Layouts.ARRAY.getSize(array));
return value;
}

@@ -212,7 +222,8 @@ public Object writeWithinDouble(DynamicObject array, int index, Object value) {
public boolean writeExtendByOne(VirtualFrame frame, DynamicObject array, int index, boolean value) {
ensureCapacityNode.executeEnsureCapacity(frame, array, index + 1);
((Object[]) Layouts.ARRAY.getStore(array))[index] = value;
ArrayNodes.setStore(array, Layouts.ARRAY.getStore(array), index + 1);
Layouts.ARRAY.setStore(array, Layouts.ARRAY.getStore(array));
Layouts.ARRAY.setSize(array, index + 1);
return value;
}

@@ -222,7 +233,8 @@ public boolean writeExtendByOne(VirtualFrame frame, DynamicObject array, int ind
public int writeExtendByOne(VirtualFrame frame, DynamicObject array, int index, int value) {
ensureCapacityNode.executeEnsureCapacity(frame, array, index + 1);
((int[]) Layouts.ARRAY.getStore(array))[index] = value;
ArrayNodes.setStore(array, Layouts.ARRAY.getStore(array), index + 1);
Layouts.ARRAY.setStore(array, Layouts.ARRAY.getStore(array));
Layouts.ARRAY.setSize(array, index + 1);
return value;
}

@@ -232,7 +244,8 @@ public int writeExtendByOne(VirtualFrame frame, DynamicObject array, int index,
public int writeExtendByOneIntIntoLong(VirtualFrame frame, DynamicObject array, int index, int value) {
ensureCapacityNode.executeEnsureCapacity(frame, array, index + 1);
((long[]) Layouts.ARRAY.getStore(array))[index] = value;
ArrayNodes.setStore(array, Layouts.ARRAY.getStore(array), index + 1);
Layouts.ARRAY.setStore(array, Layouts.ARRAY.getStore(array));
Layouts.ARRAY.setSize(array, index + 1);
return value;
}

@@ -242,7 +255,8 @@ public int writeExtendByOneIntIntoLong(VirtualFrame frame, DynamicObject array,
public long writeExtendByOne(VirtualFrame frame, DynamicObject array, int index, long value) {
ensureCapacityNode.executeEnsureCapacity(frame, array, index + 1);
((long[]) Layouts.ARRAY.getStore(array))[index] = value;
ArrayNodes.setStore(array, Layouts.ARRAY.getStore(array), index + 1);
Layouts.ARRAY.setStore(array, Layouts.ARRAY.getStore(array));
Layouts.ARRAY.setSize(array, index + 1);
return value;
}

@@ -252,7 +266,8 @@ public long writeExtendByOne(VirtualFrame frame, DynamicObject array, int index,
public double writeExtendByOne(VirtualFrame frame, DynamicObject array, int index, double value) {
ensureCapacityNode.executeEnsureCapacity(frame, array, index + 1);
((double[]) Layouts.ARRAY.getStore(array))[index] = value;
ArrayNodes.setStore(array, Layouts.ARRAY.getStore(array), index + 1);
Layouts.ARRAY.setStore(array, Layouts.ARRAY.getStore(array));
Layouts.ARRAY.setSize(array, index + 1);
return value;
}

@@ -262,7 +277,8 @@ public double writeExtendByOne(VirtualFrame frame, DynamicObject array, int inde
public DynamicObject writeExtendByOne(VirtualFrame frame, DynamicObject array, int index, DynamicObject value) {
ensureCapacityNode.executeEnsureCapacity(frame, array, index + 1);
((Object[]) Layouts.ARRAY.getStore(array))[index] = value;
ArrayNodes.setStore(array, Layouts.ARRAY.getStore(array), index + 1);
Layouts.ARRAY.setStore(array, Layouts.ARRAY.getStore(array));
Layouts.ARRAY.setSize(array, index + 1);
return value;
}

@@ -272,7 +288,8 @@ public DynamicObject writeExtendByOne(VirtualFrame frame, DynamicObject array, i
public int writeObjectExtendByOne(VirtualFrame frame, DynamicObject array, int index, int value) {
ensureCapacityNode.executeEnsureCapacity(frame, array, index + 1);
((Object[]) Layouts.ARRAY.getStore(array))[index] = value;
ArrayNodes.setStore(array, Layouts.ARRAY.getStore(array), index + 1);
Layouts.ARRAY.setStore(array, Layouts.ARRAY.getStore(array));
Layouts.ARRAY.setSize(array, index + 1);
return value;
}

@@ -290,7 +307,8 @@ public Object writeBeyondPrimitive(VirtualFrame frame, DynamicObject array, int
}

objectStore[index] = value;
ArrayNodes.setStore(array, Layouts.ARRAY.getStore(array), index + 1);
Layouts.ARRAY.setStore(array, Layouts.ARRAY.getStore(array));
Layouts.ARRAY.setSize(array, index + 1);
return value;
}

@@ -306,7 +324,8 @@ public Object writeBeyondObject(VirtualFrame frame, DynamicObject array, int ind
}

objectStore[index] = value;
ArrayNodes.setStore(array, Layouts.ARRAY.getStore(array), index + 1);
Layouts.ARRAY.setStore(array, Layouts.ARRAY.getStore(array));
Layouts.ARRAY.setSize(array, index + 1);
return value;
}

Original file line number Diff line number Diff line change
@@ -46,7 +46,8 @@ public boolean ensureCapacityInt(DynamicObject array, int requiredCapacity) {
final int[] store = (int[]) Layouts.ARRAY.getStore(array);

if (allocateProfile.profile(store.length < requiredCapacity)) {
ArrayNodes.setStore(array, Arrays.copyOf(store, ArrayUtils.capacity(store.length, requiredCapacity)), Layouts.ARRAY.getSize(array));
Layouts.ARRAY.setStore(array, Arrays.copyOf(store, ArrayUtils.capacity(store.length, requiredCapacity)));
Layouts.ARRAY.setSize(array, Layouts.ARRAY.getSize(array));
return true;
} else {
return false;
@@ -60,7 +61,8 @@ public boolean ensureCapacityLong(DynamicObject array, int requiredCapacity) {
final long[] store = (long[]) Layouts.ARRAY.getStore(array);

if (allocateProfile.profile(store.length < requiredCapacity)) {
ArrayNodes.setStore(array, Arrays.copyOf(store, ArrayUtils.capacity(store.length, requiredCapacity)), Layouts.ARRAY.getSize(array));
Layouts.ARRAY.setStore(array, Arrays.copyOf(store, ArrayUtils.capacity(store.length, requiredCapacity)));
Layouts.ARRAY.setSize(array, Layouts.ARRAY.getSize(array));
return true;
} else {
return false;
@@ -74,7 +76,8 @@ public boolean ensureCapacityDouble(DynamicObject array, int requiredCapacity) {
final double[] store = (double[]) Layouts.ARRAY.getStore(array);

if (allocateProfile.profile(store.length < requiredCapacity)) {
ArrayNodes.setStore(array, Arrays.copyOf(store, ArrayUtils.capacity(store.length, requiredCapacity)), Layouts.ARRAY.getSize(array));
Layouts.ARRAY.setStore(array, Arrays.copyOf(store, ArrayUtils.capacity(store.length, requiredCapacity)));
Layouts.ARRAY.setSize(array, Layouts.ARRAY.getSize(array));
return true;
} else {
return false;
@@ -88,7 +91,8 @@ public boolean ensureCapacityObject(DynamicObject array, int requiredCapacity) {
final Object[] store = (Object[]) Layouts.ARRAY.getStore(array);

if (allocateProfile.profile(store.length < requiredCapacity)) {
ArrayNodes.setStore(array, Arrays.copyOf(store, ArrayUtils.capacity(store.length, requiredCapacity)), Layouts.ARRAY.getSize(array));
Layouts.ARRAY.setStore(array, Arrays.copyOf(store, ArrayUtils.capacity(store.length, requiredCapacity)));
Layouts.ARRAY.setSize(array, Layouts.ARRAY.getSize(array));
return true;
} else {
return false;
Original file line number Diff line number Diff line change
@@ -40,7 +40,9 @@ public GeneralizeArrayNode(RubyContext context, SourceSection sourceSection) {
guards={"isRubyArray(array)", "isNullArray(array)"}
)
public DynamicObject generalizeNull(DynamicObject array, int requiredCapacity) {
ArrayNodes.setStore(array, new Object[requiredCapacity], Layouts.ARRAY.getSize(array));
Object store = new Object[requiredCapacity];
Layouts.ARRAY.setStore(array, store);
Layouts.ARRAY.setSize(array, Layouts.ARRAY.getSize(array));
return array;
}

@@ -49,7 +51,8 @@ public DynamicObject generalizeNull(DynamicObject array, int requiredCapacity) {
)
public DynamicObject generalizeInt(DynamicObject array, int requiredCapacity) {
final int[] intStore = (int[]) Layouts.ARRAY.getStore(array);
ArrayNodes.setStore(array, ArrayUtils.boxExtra(intStore, requiredCapacity - intStore.length), Layouts.ARRAY.getSize(array));
Layouts.ARRAY.setStore(array, ArrayUtils.boxExtra(intStore, requiredCapacity - intStore.length));
Layouts.ARRAY.setSize(array, Layouts.ARRAY.getSize(array));
return array;
}

@@ -58,7 +61,8 @@ public DynamicObject generalizeInt(DynamicObject array, int requiredCapacity) {
)
public DynamicObject generalizeLong(DynamicObject array, int requiredCapacity) {
final long[] intStore = (long[]) Layouts.ARRAY.getStore(array);
ArrayNodes.setStore(array, ArrayUtils.boxExtra(intStore, requiredCapacity - intStore.length), Layouts.ARRAY.getSize(array));
Layouts.ARRAY.setStore(array, ArrayUtils.boxExtra(intStore, requiredCapacity - intStore.length));
Layouts.ARRAY.setSize(array, Layouts.ARRAY.getSize(array));
return array;
}

@@ -67,7 +71,8 @@ public DynamicObject generalizeLong(DynamicObject array, int requiredCapacity) {
)
public DynamicObject generalizeDouble(DynamicObject array, int requiredCapacity) {
final double[] intStore = (double[]) Layouts.ARRAY.getStore(array);
ArrayNodes.setStore(array, ArrayUtils.boxExtra(intStore, requiredCapacity - intStore.length), Layouts.ARRAY.getSize(array));
Layouts.ARRAY.setStore(array, ArrayUtils.boxExtra(intStore, requiredCapacity - intStore.length));
Layouts.ARRAY.setSize(array, Layouts.ARRAY.getSize(array));
return array;
}

Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.array.ArrayMirror;
import org.jruby.truffle.runtime.array.ArrayReflector;
import org.jruby.truffle.runtime.layouts.Layouts;

@NodeChildren({
@@ -43,22 +44,22 @@ public DynamicObject popOneEmpty(DynamicObject array) {

@Specialization(guards = {"isRubyArray(array)", "!isEmptyArray(array)", "isIntArray(array)"})
public Object popOneInteger(DynamicObject array) {
return popOneGeneric(array, ArrayMirror.reflect((int[]) Layouts.ARRAY.getStore(array)));
return popOneGeneric(array, ArrayReflector.reflect((int[]) Layouts.ARRAY.getStore(array)));
}

@Specialization(guards = {"isRubyArray(array)", "!isEmptyArray(array)", "isLongArray(array)"})
public Object popOneLong(DynamicObject array) {
return popOneGeneric(array, ArrayMirror.reflect((long[]) Layouts.ARRAY.getStore(array)));
return popOneGeneric(array, ArrayReflector.reflect((long[]) Layouts.ARRAY.getStore(array)));
}

@Specialization(guards = {"isRubyArray(array)", "!isEmptyArray(array)", "isDoubleArray(array)"})
public Object popOneDouble(DynamicObject array) {
return popOneGeneric(array, ArrayMirror.reflect((double[]) Layouts.ARRAY.getStore(array)));
return popOneGeneric(array, ArrayReflector.reflect((double[]) Layouts.ARRAY.getStore(array)));
}

@Specialization(guards = {"isRubyArray(array)", "!isEmptyArray(array)", "isObjectArray(array)"})
public Object popOneObject(DynamicObject array) {
return popOneGeneric(array, ArrayMirror.reflect((Object[]) Layouts.ARRAY.getStore(array)));
return popOneGeneric(array, ArrayReflector.reflect((Object[]) Layouts.ARRAY.getStore(array)));
}

private Object popOneGeneric(DynamicObject array, ArrayMirror storeMirror) {
Original file line number Diff line number Diff line change
@@ -282,7 +282,8 @@ public Object construct(VirtualFrame frame, DynamicObject hashClass, Object[] ar

@Specialization
public Object constructFallback(VirtualFrame frame, DynamicObject hashClass, Object[] args) {
return ruby(frame, "_constructor_fallback(*args)", "args", ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), args));
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
return ruby(frame, "_constructor_fallback(*args)", "args", ArrayNodes.createGeneralArray(arrayClass, args, args.length));
}

public static boolean isSmallArrayOfPairs(Object[] args) {
@@ -1300,8 +1301,10 @@ public DynamicObject shiftPackedArray(DynamicObject hash) {
Layouts.HASH.setSize(hash, Layouts.HASH.getSize(hash) - 1);

assert verifyStore(hash);

return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), key, value);

DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
Object[] objects = new Object[]{key, value};
return ArrayNodes.createGeneralArray(arrayClass, objects, objects.length);
}

@Specialization(guards = {"!isEmptyHash(hash)", "isBucketHash(hash)"})
@@ -1360,7 +1363,9 @@ public DynamicObject shiftBuckets(DynamicObject hash) {

assert verifyStore(hash);

return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), key, value);
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
Object[] objects = new Object[]{key, value};
return ArrayNodes.createGeneralArray(arrayClass, objects, objects.length);
}

}
Original file line number Diff line number Diff line change
@@ -14,9 +14,9 @@
import com.oracle.truffle.api.object.DynamicObject;
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.ModuleOperations;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.ArrayOperations;
import org.jruby.truffle.runtime.layouts.Layouts;

/**
@@ -41,7 +41,7 @@ public boolean canHandle(VirtualFrame frame, DynamicObject exception) {

final DynamicObject exceptionRubyClass = Layouts.BASIC_OBJECT.getLogicalClass(exception);

for (Object handlingClass : ArrayNodes.slowToArray(handlingClasses)) {
for (Object handlingClass : ArrayOperations.toIterable(handlingClasses)) {
if (ModuleOperations.assignableTo(exceptionRubyClass, (DynamicObject) handlingClass)) {
return true;
}
Original file line number Diff line number Diff line change
@@ -62,8 +62,7 @@ public DynamicObject dToA(double value) {

final int sign = value < 0 ? 1 : 0;

return ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(),
new Object[]{createString(string), decimal, sign, string.length()}, 4);
return ArrayNodes.createGeneralArray(getContext().getCoreLibrary().getArrayClass(), new Object[]{createString(string), decimal, sign, string.length()}, 4);
}

}
Original file line number Diff line number Diff line change
@@ -53,6 +53,7 @@
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.ArrayOperations;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.truffle.runtime.sockets.FDSet;
import org.jruby.truffle.runtime.sockets.FDSetFactory;
@@ -431,7 +432,8 @@ public int write(DynamicObject file, DynamicObject string) {
int written = posix().write(fd, buffer, buffer.remaining());

if (written == -1) {
throw new UnsupportedOperationException();
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().errnoError(posix().errno(), this));
}

buffer.position(buffer.position() + written);
@@ -571,7 +573,7 @@ public IOSelectPrimitiveNode(RubyContext context, SourceSection sourceSection) {
@TruffleBoundary
@Specialization(guards = {"isRubyArray(readables)", "isNil(writables)", "isNil(errorables)"})
public Object select(DynamicObject readables, DynamicObject writables, DynamicObject errorables, int timeout) {
final Object[] readableObjects = ArrayNodes.slowToArray(readables);
final Object[] readableObjects = ArrayOperations.toObjectArray(readables);
final int[] readableFds = getFileDescriptors(readables);

final FDSet readableSet = fdSetFactory.create();
@@ -596,16 +598,19 @@ public Integer block() throws InterruptedException {
return nil();
}

return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(),
getSetObjects(readableObjects, readableFds, readableSet),
ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass()),
ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass()));
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
Object[] objects = new Object[]{};
DynamicObject arrayClass1 = getContext().getCoreLibrary().getArrayClass();
Object[] objects1 = new Object[]{};
DynamicObject arrayClass2 = getContext().getCoreLibrary().getArrayClass();
Object[] objects2 = new Object[]{getSetObjects(readableObjects, readableFds, readableSet), ArrayNodes.createGeneralArray(arrayClass1, objects1, objects1.length), ArrayNodes.createGeneralArray(arrayClass, objects, objects.length)};
return ArrayNodes.createGeneralArray(arrayClass2, objects2, objects2.length);
}

@TruffleBoundary
@Specialization(guards = { "isNil(readables)", "isRubyArray(writables)", "isNil(errorables)" })
public Object selectNilReadables(DynamicObject readables, DynamicObject writables, DynamicObject errorables, int timeout) {
final Object[] writableObjects = ArrayNodes.slowToArray(writables);
final Object[] writableObjects = ArrayOperations.toObjectArray(writables);
final int[] writableFds = getFileDescriptors(writables);

final FDSet writableSet = fdSetFactory.create();
@@ -630,16 +635,19 @@ public Integer block() throws InterruptedException {
return nil();
}

return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(),
ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass()),
getSetObjects(writableObjects, writableFds, writableSet),
ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass()));
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
Object[] objects = new Object[]{};
DynamicObject arrayClass1 = getContext().getCoreLibrary().getArrayClass();
Object[] objects1 = new Object[]{};
DynamicObject arrayClass2 = getContext().getCoreLibrary().getArrayClass();
Object[] objects2 = new Object[]{ArrayNodes.createGeneralArray(arrayClass1, objects1, objects1.length), getSetObjects(writableObjects, writableFds, writableSet), ArrayNodes.createGeneralArray(arrayClass, objects, objects.length)};
return ArrayNodes.createGeneralArray(arrayClass2, objects2, objects2.length);
}

private int[] getFileDescriptors(DynamicObject fileDescriptorArray) {
assert RubyGuards.isRubyArray(fileDescriptorArray);

final Object[] objects = ArrayNodes.slowToArray(fileDescriptorArray);
final Object[] objects = ArrayOperations.toObjectArray(fileDescriptorArray);

final int[] fileDescriptors = new int[objects.length];

Original file line number Diff line number Diff line change
@@ -175,7 +175,9 @@ public DynamicObject stringAwkSplit(DynamicObject string, int lim) {

if (len > 0 && (limit || len > b || lim < 0)) ret.add(makeString(string, b, len - b));

return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), ret.toArray());
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
Object[] objects = ret.toArray();
return ArrayNodes.createGeneralArray(arrayClass, objects, objects.length);
}

private DynamicObject makeString(DynamicObject source, int index, int length) {
Original file line number Diff line number Diff line change
@@ -461,12 +461,14 @@ public DynamicObject getSection(DynamicObject section) {
stringValue = value.toString();
}

sectionKeyValues.add(ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(),
createString(key),
createString(stringValue)));
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
Object[] objects = new Object[]{createString(key), createString(stringValue)};
sectionKeyValues.add(ArrayNodes.createGeneralArray(arrayClass, objects, objects.length));
}

return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), sectionKeyValues.toArray());
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
Object[] objects = sectionKeyValues.toArray();
return ArrayNodes.createGeneralArray(arrayClass, objects, objects.length);
}

}
@@ -535,7 +537,9 @@ public Integer block() throws InterruptedException {
stopsig = PosixShim.WAIT_MACROS.WSTOPSIG(status);
}

return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), output, termsig, stopsig, pid);
DynamicObject arrayClass = getContext().getCoreLibrary().getArrayClass();
Object[] objects = new Object[]{output, termsig, stopsig, pid};
return ArrayNodes.createGeneralArray(arrayClass, objects, objects.length);
}

}
Original file line number Diff line number Diff line change
@@ -18,12 +18,12 @@
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.cast.ProcOrNullNode;
import org.jruby.truffle.nodes.cast.ProcOrNullNodeGen;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.nodes.methods.CallMethodNode;
import org.jruby.truffle.nodes.methods.CallMethodNodeGen;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.ArrayOperations;
import org.jruby.truffle.runtime.methods.InternalMethod;

/**
@@ -77,7 +77,7 @@ public final Object execute(VirtualFrame frame) {
final Object[] argumentsArray;
if (isSplatted) {
// TODO(CS): need something better to splat the arguments array
argumentsArray = ArrayNodes.slowToArray((DynamicObject) argumentsObjects[0]);
argumentsArray = ArrayOperations.toObjectArray((DynamicObject) argumentsObjects[0]);
} else {
argumentsArray = argumentsObjects;
}
Original file line number Diff line number Diff line change
@@ -19,13 +19,13 @@
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.cast.ProcOrNullNode;
import org.jruby.truffle.nodes.cast.ProcOrNullNodeGen;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.nodes.methods.CallMethodNode;
import org.jruby.truffle.nodes.methods.CallMethodNodeGen;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.array.ArrayUtils;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.ArrayOperations;
import org.jruby.truffle.runtime.methods.InternalMethod;

import java.util.Arrays;
@@ -74,7 +74,7 @@ public final Object execute(VirtualFrame frame) {
// TODO (eregon, 22 July 2015): Assumes rest arg is last, not true if post or keyword args.
final Object restArg = superArguments[superArguments.length - 1];
assert RubyGuards.isRubyArray(restArg);
final Object[] restArgs = ArrayNodes.slowToArray((DynamicObject) restArg);
final Object[] restArgs = ArrayOperations.toObjectArray((DynamicObject) restArg);
final int restArgIndex = reloadNodes.length - 1;
superArguments = Arrays.copyOf(superArguments, restArgIndex + restArgs.length);
ArrayUtils.arraycopy(restArgs, 0, superArguments, restArgIndex, restArgs.length);
Original file line number Diff line number Diff line change
@@ -17,10 +17,10 @@
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.ArrayOperations;

/**
* Yield to the current block.
@@ -66,7 +66,7 @@ private Object[] unsplat(Object[] argumentsObjects) {
// TOOD(CS): what is the error behaviour here?
assert argumentsObjects.length == 1;
assert RubyGuards.isRubyArray(argumentsObjects[0]);
return ArrayNodes.slowToArray(((DynamicObject) argumentsObjects[0]));
return ArrayOperations.toObjectArray(((DynamicObject) argumentsObjects[0]));
}

@Override
Loading