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

Commits on Jun 9, 2016

  1. Use Java's Arrays.sort

    Java's Arrays.sort more robust and is faster is certain cases.
    
    See #3919 and
    https://github.com/sri/jruby-sort-benchmark.
    sri committed Jun 9, 2016
    Copy the full SHA
    5502160 View commit details

Commits on Jun 14, 2016

  1. Copy the full SHA
    55cef79 View commit details
  2. HEADIUS

    headius committed Jun 14, 2016
    Copy the full SHA
    141c3ab View commit details

Commits on Jun 15, 2016

  1. Copy the full SHA
    ddf6701 View commit details
  2. Copy the full SHA
    03e4f7a View commit details
  3. Copy the full SHA
    9846105 View commit details
  4. Copy the full SHA
    07cdf83 View commit details
  5. Copy the full SHA
    e06fb98 View commit details
  6. Copy the full SHA
    fd4c8d3 View commit details
  7. Fix #3969: AddMissingInts: Rescue bbs shd. receive state from pred.in

    * This (conservatively) ensures that even if the very first instruction
      of the BB might raise an exception, the rescue block sees state from
      entry of the BB, rather than (optimistically) from the end of the BB
      which control might never reach.
    
    * The conservative assumption also matches the JVM verifier's assumption
      and should ensure that generated bytecode passes the verifier
    
    * Verified that the generated IR is correct on the following snippet.
    --------
    def foo
      saved = bar()
    ensure
      bar(saved)
    end
    --------
    subbuss committed Jun 15, 2016
    Copy the full SHA
    f3f5776 View commit details
  8. Deprecate the Qsort class

    sri committed Jun 15, 2016
    2
    Copy the full SHA
    192f7a3 View commit details
  9. Merge pull request #3961 from sri/use-java-native-sort

    Use Java's Arrays.sort
    enebo authored Jun 15, 2016
    Copy the full SHA
    f434a33 View commit details
  10. Copy the full SHA
    16f47ce View commit details
  11. Copy the full SHA
    3e415c8 View commit details
  12. Copy the full SHA
    9dfd839 View commit details
  13. Copy the full SHA
    5e0a335 View commit details
  14. 4
    Copy the full SHA
    99e11a9 View commit details
  15. EQQInstr has added a splattedValue field. This new field is used

    to differentiate between a single object which happens to be an
    array vs an array which happens to represent a set of values we
    want to call eqq on.  The discriminator in IRBuilder is whether
    we see Args{Cat,Push}Node or SplatNode (at least for when
    statements...it is possible we need this for rescue_eqq too?).
    enebo committed Jun 15, 2016
    Copy the full SHA
    3a37205 View commit details
  16. [Truffle] Split test gems and ecosystem, and allow gems to be used fr…

    …om somewhere else rather than installing.
    chrisseaton committed Jun 15, 2016
    1
    Copy the full SHA
    3acdc1d View commit details

Commits on Jun 16, 2016

  1. Copy the full SHA
    4c3a88b View commit details
  2. Copy the full SHA
    2ef0858 View commit details
  3. fix Socket's #recv_nonblock and UDPSocket#recvfrom_nonblock

    returning :wait_readable instead of raising when op would block
    kares committed Jun 16, 2016
    Copy the full SHA
    239e1de View commit details
  4. Copy the full SHA
    388030b View commit details
  5. Copy the full SHA
    3a1a9e4 View commit details
  6. avoid copy-ing byte[] from buffer to byte-list

    + hide method (receiving a buffer param) used internaly
    kares committed Jun 16, 2016
    Copy the full SHA
    5ddb20a View commit details
  7. Copy the full SHA
    ae51596 View commit details
  8. Copy the full SHA
    f4c6f1c View commit details
  9. Copy the full SHA
    d6c5b01 View commit details
  10. Merge branch 'master' into truffle-head

    # Conflicts:
    #	.travis.yml
    chrisseaton committed Jun 16, 2016
    Copy the full SHA
    c73342d View commit details
  11. Copy the full SHA
    bf91bca View commit details
Showing with 555 additions and 307 deletions.
  1. +12 −1 .travis.yml
  2. +52 −10 ci.hocon
  3. +16 −21 core/src/main/java/org/jruby/Ruby.java
  4. +2 −3 core/src/main/java/org/jruby/RubyArray.java
  5. +4 −4 core/src/main/java/org/jruby/RubyString.java
  6. +16 −26 core/src/main/java/org/jruby/ext/socket/RubyBasicSocket.java
  7. +54 −56 core/src/main/java/org/jruby/ext/socket/RubyUDPSocket.java
  8. +5 −8 core/src/main/java/org/jruby/ext/socket/RubyUNIXSocket.java
  9. +4 −6 core/src/main/java/org/jruby/ir/IRBuilder.java
  10. +5 −3 core/src/main/java/org/jruby/ir/dataflow/analyses/DefinedVariableNode.java
  11. +23 −4 core/src/main/java/org/jruby/ir/instructions/EQQInstr.java
  12. +8 −3 core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
  13. +2 −2 core/src/main/java/org/jruby/ir/targets/Bootstrap.java
  14. +2 −2 core/src/main/java/org/jruby/ir/targets/IRBytecodeAdapter.java
  15. +16 −4 core/src/main/java/org/jruby/ir/targets/IRBytecodeAdapter6.java
  16. +25 −2 core/src/main/java/org/jruby/ir/targets/IRBytecodeAdapter7.java
  17. +5 −8 core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
  18. +1 −1 core/src/main/java/org/jruby/runtime/encoding/EncodingService.java
  19. +51 −25 core/src/main/java/org/jruby/runtime/invokedynamic/MathLinker.java
  20. +1 −1 core/src/main/java/org/jruby/util/Qsort.java
  21. +0 −1 core/src/main/ruby/jruby/kernel/kernel.rb
  22. +50 −0 mx.jruby/mx_jruby.py
  23. +8 −0 spec/compiler/general_spec.rb
  24. +0 −2 spec/truffle/tags/core/string/split_tags.txt
  25. +108 −85 test/jruby/test_socket.rb
  26. +0 −1 test/mri/excludes/TestCase.rb
  27. +8 −0 test/truffle/ecosystem/ecosystem.sh
  28. +1 −1 test/truffle/{gems → ecosystem}/rails-app.sh
  29. 0 test/truffle/{gems → ecosystem}/rails-app/.gitignore
  30. 0 test/truffle/{gems → ecosystem}/rails-app/.jruby+truffle.yaml
  31. 0 test/truffle/{gems → ecosystem}/rails-app/Gemfile
  32. 0 test/truffle/{gems → ecosystem}/rails-app/Gemfile.lock
  33. 0 test/truffle/{gems → ecosystem}/rails-app/Rakefile
  34. 0 test/truffle/{gems → ecosystem}/rails-app/app/assets/images/.keep
  35. 0 test/truffle/{gems → ecosystem}/rails-app/app/assets/stylesheets/application.css
  36. 0 test/truffle/{gems → ecosystem}/rails-app/app/controllers/application_controller.rb
  37. 0 test/truffle/{gems → ecosystem}/rails-app/app/controllers/concerns/.keep
  38. 0 test/truffle/{gems → ecosystem}/rails-app/app/controllers/people_controller.rb
  39. 0 test/truffle/{gems → ecosystem}/rails-app/app/helpers/application_helper.rb
  40. 0 test/truffle/{gems → ecosystem}/rails-app/app/models/concerns/.keep
  41. 0 test/truffle/{gems → ecosystem}/rails-app/app/models/person.rb
  42. 0 test/truffle/{gems → ecosystem}/rails-app/app/views/layouts/application.html.erb
  43. 0 test/truffle/{gems → ecosystem}/rails-app/app/views/people/index.erb
  44. 0 test/truffle/{gems → ecosystem}/rails-app/bin/bundle
  45. 0 test/truffle/{gems → ecosystem}/rails-app/bin/rails
  46. 0 test/truffle/{gems → ecosystem}/rails-app/bin/rake
  47. 0 test/truffle/{gems → ecosystem}/rails-app/bin/setup
  48. 0 test/truffle/{gems → ecosystem}/rails-app/config.ru
  49. 0 test/truffle/{gems → ecosystem}/rails-app/config/application.rb
  50. 0 test/truffle/{gems → ecosystem}/rails-app/config/boot.rb
  51. 0 test/truffle/{gems → ecosystem}/rails-app/config/database.yml
  52. 0 test/truffle/{gems → ecosystem}/rails-app/config/environment.rb
  53. 0 test/truffle/{gems → ecosystem}/rails-app/config/environments/development.rb
  54. 0 test/truffle/{gems → ecosystem}/rails-app/config/environments/production.rb
  55. 0 test/truffle/{gems → ecosystem}/rails-app/config/environments/test.rb
  56. 0 test/truffle/{gems → ecosystem}/rails-app/config/initializers/backtrace_silencers.rb
  57. 0 test/truffle/{gems → ecosystem}/rails-app/config/initializers/cookies_serializer.rb
  58. 0 test/truffle/{gems → ecosystem}/rails-app/config/initializers/filter_parameter_logging.rb
  59. 0 test/truffle/{gems → ecosystem}/rails-app/config/initializers/inflections.rb
  60. 0 test/truffle/{gems → ecosystem}/rails-app/config/initializers/mime_types.rb
  61. 0 test/truffle/{gems → ecosystem}/rails-app/config/initializers/session_store.rb
  62. 0 test/truffle/{gems → ecosystem}/rails-app/config/initializers/wrap_parameters.rb
  63. 0 test/truffle/{gems → ecosystem}/rails-app/config/locales/en.yml
  64. 0 test/truffle/{gems → ecosystem}/rails-app/config/routes.rb
  65. 0 test/truffle/{gems → ecosystem}/rails-app/config/secrets.yml
  66. 0 test/truffle/{gems → ecosystem}/rails-app/lib/assets/.keep
  67. 0 test/truffle/{gems → ecosystem}/rails-app/lib/tasks/.keep
  68. 0 test/truffle/{gems → ecosystem}/rails-app/log/.keep
  69. 0 test/truffle/{gems → ecosystem}/rails-app/public/404.html
  70. 0 test/truffle/{gems → ecosystem}/rails-app/public/422.html
  71. 0 test/truffle/{gems → ecosystem}/rails-app/public/500.html
  72. 0 test/truffle/{gems → ecosystem}/rails-app/public/favicon.ico
  73. 0 test/truffle/{gems → ecosystem}/rails-app/public/robots.txt
  74. 0 test/truffle/{gems → ecosystem}/rails-app/public/stylesheets/application.css
  75. 0 test/truffle/{gems → ecosystem}/rails-app/public/stylesheets/kube.css
  76. 0 test/truffle/{gems → ecosystem}/rails-app/test/controllers/.keep
  77. 0 test/truffle/{gems → ecosystem}/rails-app/test/fixtures/.keep
  78. 0 test/truffle/{gems → ecosystem}/rails-app/test/helpers/.keep
  79. 0 test/truffle/{gems → ecosystem}/rails-app/test/integration/.keep
  80. 0 test/truffle/{gems → ecosystem}/rails-app/test/mailers/.keep
  81. 0 test/truffle/{gems → ecosystem}/rails-app/test/models/.keep
  82. 0 test/truffle/{gems → ecosystem}/rails-app/test/test_helper.rb
  83. 0 test/truffle/{gems → ecosystem}/rails-app/vendor/assets/javascripts/.keep
  84. 0 test/truffle/{gems → ecosystem}/rails-app/vendor/assets/stylesheets/.keep
  85. +5 −4 test/truffle/gems/execjs.sh
  86. +0 −6 test/truffle/gems/gem-testing.sh
  87. +9 −0 test/truffle/gems/install-gems.sh
  88. +4 −2 test/truffle/gems/rack-server.sh
  89. +8 −5 test/truffle/gems/sinatra-server.sh
  90. +49 −9 tool/jt.rb
  91. +1 −1 truffle/src/main/ruby/core/splitter.rb
13 changes: 12 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -43,9 +43,20 @@ matrix:
jdk: oraclejdk8
- env: JT='test integration'
jdk: oraclejdk8
- env:
- COMMAND=test/truffle/gems/install-gems.sh
- JT='test gems'
jdk: oraclejdk8
- env:
- JAVA_OPTS="$JAVA_OPTS -Xmx512m"
- HAS_REDIS=true
- JT='test ecosystem'
jdk: oraclejdk8
- env: JT='test tck'
jdk: oraclejdk8
- env: JT=check_ambiguous_arguments SKIP_BUILD=true
- env:
- JT=check_ambiguous_arguments
- SKIP_BUILD=true
jdk: oraclejdk8
allow_failures:
- env: JT='test mri'
62 changes: 52 additions & 10 deletions ci.hocon
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ common: {

setup: ${common-setup}

timelimit: "30:00"
timelimit: "01:00:00"
}

no-graal: {
@@ -35,14 +35,15 @@ no-graal: {

graal-core: {
setup: ${common-setup} [
[rm, -rf, mx.jruby],
[mv, mx.jruby, temp_mx],
[mkdir, graal-workspace],
[cd, graal-workspace],
[mx, sclone, --kind, git, "https://github.com/graalvm/graal-core.git", graal-core],
[cd, graal-core],
[mx, sforceimports],
[mx, --vm, server, build],
[cd, ../..]
[cd, ../..],
[mv, temp_mx, mx.jruby]
]

environment: {
@@ -68,19 +69,39 @@ graalvm: {
}
}

jruby-noindy: {
jruby-noindy-metrics: {
environment: {
GUEST_VM: jruby,
GUEST_VM_CONFIG: noindy,
JRUBY_OPTS: "-X-T -Xcompile.invokedynamic=false"
JRUBY_OPTS: "-X-T -Xcompile.invokedynamic=false",
MX_BENCHMARK_OPTS: --no-graal
}
}

jruby-indy: {
jruby-noindy-benchmark: {
environment: {
GUEST_VM: jruby,
GUEST_VM_CONFIG: noindy,
JRUBY_OPTS: "-X-T -X+C -Xcompile.invokedynamic=false",
MX_BENCHMARK_OPTS: --no-graal
}
}

jruby-indy-metrics: {
environment: {
GUEST_VM: jruby,
GUEST_VM_CONFIG: indy,
JRUBY_OPTS: "-X-T -Xcompile.invokedynamic=true",
MX_BENCHMARK_OPTS: --no-graal
}
}

jruby-indy-benchmark: {
environment: {
GUEST_VM: jruby,
GUEST_VM_CONFIG: indy,
JRUBY_OPTS: "-X-T -Xcompile.invokedynamic=true"
JRUBY_OPTS: "-X-T -X+C -Xcompile.invokedynamic=true",
MX_BENCHMARK_OPTS: --no-graal
}
}

@@ -129,6 +150,17 @@ compiler-metrics: {
] ${post-process-and-upload-results}
}

setup-benchmarks: [
[mx, sclone, --kind, git, "https://github.com/jruby/benchmark-interface.git", benchmark-interface],
[mx, sclone, --kind, git, "https://github.com/jruby/all-ruby-benchmarks.git", all-ruby-benchmarks]
]

classic-benchmarks: {
run: ${setup-benchmarks} [
[mx, benchmark, classic]
] ${post-process-and-upload-results}
}

builds: [
{name: ruby-test-fast} ${common} ${gate-caps} {run: [${jt} [test, fast]]},
{name: ruby-test-specs-command-line} ${common} ${gate-caps} {run: [${jt} [test, specs, ":command_line"]]},
@@ -137,14 +169,24 @@ builds: [
{name: ruby-test-specs-library} ${common} ${gate-caps} {run: [${jt} [test, specs, ":library"]]},
{name: ruby-test-specs-truffle} ${common} ${gate-caps} {run: [${jt} [test, specs, ":truffle"]]},
{name: ruby-test-integration} ${common} ${gate-caps} {run: [${jt} [test, integration]]},
{name: ruby-test-gems} ${common} ${gate-caps} {
setup: ${common-setup} [[mx, sclone, --kind, git, "https://github.com/jruby/jruby-truffle-gem-test-pack.git", jruby-truffle-gem-test-pack]]
environment: {GEM_HOME: jruby-truffle-gem-test-pack/gems}
run: [${jt} [test, gems]]
},
{name: ruby-test-tck} ${common} ${gate-caps} {run: [${jt} [test, tck]]},
{name: ruby-test-tarball} ${common} ${gate-caps} {run: [${jt} [tarball]]},

{name: ruby-test-compiler-graal-core} ${common} ${graal-core} ${gate-caps} {run: [${jt} [test, compiler]]},
{name: ruby-test-compiler-graalvm} ${common} ${graalvm} ${gate-caps} {run: [${jt} [test, compiler]]},

{name: ruby-metrics-noindy} ${common} ${no-graal} ${daily-bench-caps} ${jruby-noindy} ${metrics},
{name: ruby-metrics-indy} ${common} ${no-graal} ${daily-bench-caps} ${jruby-indy} ${metrics},
//{name: ruby-metrics-noindy} ${common} ${no-graal} ${daily-bench-caps} ${jruby-noindy-metrics} ${metrics},
//{name: ruby-metrics-indy} ${common} ${no-graal} ${daily-bench-caps} ${jruby-indy-metrics} ${metrics},
{name: ruby-metrics-truffle} ${common} ${no-graal} ${bench-caps} ${jruby-truffle} ${metrics},
{name: ruby-metrics-compiler} ${common} ${graalvm} ${bench-caps} ${jruby-truffle} ${compiler-metrics}
{name: ruby-metrics-compiler-graalvm} ${common} ${graalvm} ${bench-caps} ${jruby-truffle} ${compiler-metrics},

//{name: ruby-benchmarks-classic-noindy} ${common} ${no-graal} ${daily-bench-caps} ${jruby-noindy-benchmark} ${classic-benchmarks},
//{name: ruby-benchmarks-classic-indy} ${common} ${no-graal} ${daily-bench-caps} ${jruby-indy-benchmark} ${classic-benchmarks},
{name: ruby-benchmarks-classic-graal-core} ${common} ${graal-core} ${bench-caps} ${jruby-truffle} ${classic-benchmarks},
{name: ruby-benchmarks-classic-graalvm} ${common} ${graalvm} ${bench-caps} ${jruby-truffle} ${classic-benchmarks}
]
37 changes: 16 additions & 21 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -727,22 +727,10 @@ private RootNode addGetsLoop(RootNode oldRoot, boolean printing, boolean process
*
* @param scriptNode The root node of the script to be executed
* bytecode before execution
* @param wrap whether to wrap the execution in an anonymous module
* @return The result of executing the script
*/
@Deprecated
public IRubyObject runNormally(Node scriptNode, boolean unused) {
return runNormally(scriptNode);
}

/**
* Run the specified script without any of the loop-processing wrapper
* code.
*
* @param scriptNode The root node of the script to be executed
* bytecode before execution
* @return The result of executing the script
*/
public IRubyObject runNormally(Node scriptNode) {
public IRubyObject runNormally(Node scriptNode, boolean wrap) {
ScriptAndCode scriptAndCode = null;
boolean compile = getInstanceConfig().getCompileMode().shouldPrecompileCLI();
if (compile || config.isShowBytecode()) {
@@ -757,7 +745,7 @@ public IRubyObject runNormally(Node scriptNode) {
return getNil();
}

return runScript(scriptAndCode.script());
return runScript(scriptAndCode.script(), wrap);
} else {
// FIXME: temporarily allowing JIT to fail for $0 and fall back on interpreter
// failForcedCompile(scriptNode);
@@ -766,6 +754,18 @@ public IRubyObject runNormally(Node scriptNode) {
}
}

/**
* Run the specified script without any of the loop-processing wrapper
* code.
*
* @param scriptNode The root node of the script to be executed
* bytecode before execution
* @return The result of executing the script
*/
public IRubyObject runNormally(Node scriptNode) {
return runNormally(scriptNode, false);
}

private ScriptAndCode precompileCLI(RootNode scriptNode) {
ScriptAndCode scriptAndCode = null;

@@ -3025,12 +3025,7 @@ public void compileAndLoadFile(String filename, InputStream in, boolean wrap) {
try {
context.setFileAndLine(scriptNode.getFile(), scriptNode.getLine());

if (config.isAssumePrinting() || config.isAssumeLoop()) {
runWithGetsLoop(scriptNode, config.isAssumePrinting(), config.isProcessLineEnds(),
config.isSplit());
} else {
runNormally(scriptNode);
}
runNormally(scriptNode, wrap);
} finally {
context.setFileAndLine(oldFile, oldLine);
}
5 changes: 2 additions & 3 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -58,7 +58,6 @@
import org.jruby.runtime.opto.Invalidator;
import org.jruby.util.ByteList;
import org.jruby.util.Pack;
import org.jruby.util.Qsort;
import org.jruby.util.RecursiveComparator;
import org.jruby.util.TypeConverter;
import org.jruby.util.io.EncodingUtils;
@@ -3276,7 +3275,7 @@ private IRubyObject sortInternal(final ThreadContext context, boolean honorOverr
final boolean stringBypass = !honorOverride || runtime.getString().isMethodBuiltin("<=>");

try {
Qsort.sort(values, begin, begin + realLength, new Comparator() {
Arrays.sort(values, begin, begin + realLength, new Comparator() {
public int compare(Object o1, Object o2) {
if (fixnumBypass && o1 instanceof RubyFixnum && o2 instanceof RubyFixnum) {
return compareFixnums((RubyFixnum) o1, (RubyFixnum) o2);
@@ -3311,7 +3310,7 @@ private IRubyObject sortInternal(final ThreadContext context, final Block block)
int length = realLength;

safeArrayCopy(values, begin, newValues, 0, length);
Qsort.sort(newValues, 0, length, new Comparator() {
Arrays.sort(newValues, 0, length, new Comparator() {
public int compare(Object o1, Object o2) {
IRubyObject obj1 = (IRubyObject) o1;
IRubyObject obj2 = (IRubyObject) o2;
8 changes: 4 additions & 4 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -1004,10 +1004,10 @@ public final void view(ByteList bytes) {
shareLevel = SHARE_LEVEL_NONE;
}

private void view(byte[]bytes) {
private void view(byte[] bytes, boolean copy) {
modifyCheck();

value = new ByteList(bytes);
value = new ByteList(bytes, copy);
shareLevel = SHARE_LEVEL_NONE;

value.invalidate();
@@ -3939,7 +3939,7 @@ private boolean end_with_pCommon(IRubyObject tmp) {
return false;
}

private static final ByteList SPACE_BYTELIST = new ByteList(ByteList.plain(" "));
private static final ByteList SPACE_BYTELIST = new ByteList(new byte[] { ' ' }, false);

private IRubyObject justify19(ThreadContext context, IRubyObject arg0, int jflag) {
Ruby runtime = context.runtime;
@@ -5444,7 +5444,7 @@ public IRubyObject freeze(ThreadContext context) {
* @deprecated
*/
public void setValue(CharSequence value) {
view(ByteList.plain(value));
view(ByteList.plain(value), false);
}

public void setValue(ByteList value) {
42 changes: 16 additions & 26 deletions core/src/main/java/org/jruby/ext/socket/RubyBasicSocket.java
Original file line number Diff line number Diff line change
@@ -57,7 +57,6 @@
import org.jruby.ast.util.ArgsUtil;
import org.jruby.ext.fcntl.FcntlLibrary;
import org.jruby.platform.Platform;
import org.jruby.runtime.Arity;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
@@ -200,51 +199,45 @@ private IRubyObject recv(ThreadContext context, IRubyObject length,

@JRubyMethod
public IRubyObject recv_nonblock(ThreadContext context, IRubyObject length) {
return recv_nonblock(context, length, context.nil, context.nil, false);
return recv_nonblock(context, length, context.nil, /* str */ null, true);
}

@JRubyMethod(required = 1, optional = 3) // (length) required = 1 handled above
public IRubyObject recv_nonblock(ThreadContext context, IRubyObject[] args) {
Ruby runtime = context.runtime;
int argc = args.length;
IRubyObject opts = ArgsUtil.getOptionsArg(context.runtime, args);
IRubyObject opts = ArgsUtil.getOptionsArg(runtime, args);
if (!opts.isNil()) argc--;

IRubyObject length = context.nil;
IRubyObject flags = length;
IRubyObject str = length;
IRubyObject length, flags, str;
length = flags = context.nil; str = null;

switch (argc) {
case 3:
str = args[2];
case 2:
flags = args[1];
case 1:
length = args[0];
case 3: str = args[2];
case 2: flags = args[1];
case 1: length = args[0];
}

boolean exception = ArgsUtil.extractKeywordArg(context, "exception", opts) != runtime.getFalse();

return recv_nonblock(context, length, flags, str, exception);
}

protected IRubyObject recv_nonblock(ThreadContext context, IRubyObject length,
IRubyObject flags, IRubyObject str, boolean ex) {
Ruby runtime = context.runtime;

protected final IRubyObject recv_nonblock(ThreadContext context,
IRubyObject length, IRubyObject flags, IRubyObject str, final boolean exception) {
// TODO: implement flags
final ByteBuffer buffer = ByteBuffer.allocate(RubyNumeric.fix2int(length));

ByteList bytes = doReceiveNonblock(context, buffer);

if (bytes == null) {
if (!ex) return runtime.newSymbol("wait_readable");
if (!exception) return context.runtime.newSymbol("wait_readable");
throw context.runtime.newErrnoEAGAINReadableError("recvfrom(2)");
}

if (str != null && !str.isNil()) {
str = str.convertToString();
((RubyString)str).setValue(bytes);
((RubyString) str).setValue(bytes);
return str;
}
return RubyString.newString(context.runtime, bytes);
@@ -504,7 +497,6 @@ public IRubyObject readmsg_nonblock(ThreadContext context, IRubyObject[] args) {
}

private ByteList doReceive(ThreadContext context, final ByteBuffer buffer) {
Ruby runtime = context.runtime;
OpenFile fptr;

fptr = getOpenFile();
@@ -517,8 +509,7 @@ private ByteList doReceive(ThreadContext context, final ByteBuffer buffer) {

if (read == 0) return null;

return new ByteList(buffer.array(), 0, buffer.position());

return new ByteList(buffer.array(), 0, buffer.position(), false);
}
catch (IOException e) {
// All errors to sysread should be SystemCallErrors, but on a closed stream
@@ -534,8 +525,7 @@ private ByteList doReceive(ThreadContext context, final ByteBuffer buffer) {
}
}

public ByteList doReceiveNonblock(ThreadContext context, final ByteBuffer buffer) {
Ruby runtime = context.runtime;
protected final ByteList doReceiveNonblock(ThreadContext context, final ByteBuffer buffer) {
Channel channel = getChannel();

if ( ! (channel instanceof SelectableChannel) ) {
@@ -557,8 +547,8 @@ public ByteList doReceiveNonblock(ThreadContext context, final ByteBuffer buffer
selectable.configureBlocking(oldBlocking);
}
}
catch(IOException e) {
throw runtime.newIOErrorFromException(e);
catch (IOException e) {
throw context.runtime.newIOErrorFromException(e);
}
}
}
@@ -791,7 +781,7 @@ public static IRubyObject set_do_not_reverse_lookup(IRubyObject recv, IRubyObjec
return set_do_not_reverse_lookup(recv.getRuntime().getCurrentContext(), recv, flag);
}

private static final ByteList FORMAT_SMALL_I = new ByteList(ByteList.plain("i"));
private static final ByteList FORMAT_SMALL_I = new ByteList(new byte[] { 'i' }, false);
protected MulticastStateManager multicastStateManager = null;

// By default we always reverse lookup unless do_not_reverse_lookup set.
Loading