Skip to content

Instantly share code, notes, and snippets.

Charles Oliver Nutter headius

Block or report user

Report or block headius

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@headius
headius / synchronize.diff
Created Dec 2, 2019
Patch to naively synchronize RubyHash to protect direct-addressing data store
View synchronize.diff
diff --git a/core/src/main/java/org/jruby/RubyHash.java b/core/src/main/java/org/jruby/RubyHash.java
index 231971b6be..a17a473e0a 100644
--- a/core/src/main/java/org/jruby/RubyHash.java
+++ b/core/src/main/java/org/jruby/RubyHash.java
@@ -697,7 +697,7 @@ public class RubyHash extends RubyObject implements Map {
IRubyObject otherKey = entryKey(entries, index);
int otherHash = hashes[index];
- if (internalKeyExist(key, hash, otherKey, otherHash)) return bin;
+ if (internalKeyExist(key, hash, otherKey, otherHash, isComparedByIdentity())) return bin;
View ack_problem.md

The problem:

For an HTTP 1.1 request. JRuby's packet sequence goes like this:

  1. The request is sent from the client
  2. The server sends a packet back with the 200 OK, headers, and ack of the request
  3. The client sends an ack of the headers
  4. The server sends the body of the request

On Linux with delayed ACK, there's around 0.04 seconds between (2) and (3), which drastically reduces throughput.

View JRuby + puma with wrk client
01:32:09.160337 IP localhost.50978 > localhost.9292: Flags [P.], seq 41:81, ack 25069, win 2388, options [nop,nop,TS val 5021972 ecr 5021972], length 40
E..\I.@.@............"$L....L..... T.P.....
.L...L..GET / HTTP/1.1
Host: localhost:9292
01:32:09.160747 IP localhost.9292 > localhost.50978: Flags [P.], seq 25069:25137, ack 81, win 342, options [nop,nop,TS val 5021972 ecr 5021972], length 68
E..x:.@.@...........$L."L......+...V.l.....
.L...L..HTTP/1.1 200 OK
Content-Type: text/plain
@headius
headius / js_from_ruby
Last active Oct 28, 2019
Calling into JavaScript from JRuby using javax.script
View js_from_ruby
>> java_import javax.script.ScriptEngineManager
=> [Java::JavaxScript::ScriptEngineManager]
>> mgr = ScriptEngineManager.new
=> #<Java::JavaxScript::ScriptEngineManager:0x780cb77>
>> js = mgr.getEngineByExtension("js")
=> #<Java::JdkNashornApiScripting::NashornScriptEngine:0x60015ef5>
>> js.eval("print(1)")
1
=> nil
>>>
@headius
headius / output.txt
Last active Sep 19, 2019
JRuby's new --environment flag
View output.txt
[] ~/projects/jruby $ jruby.bash --environment --dev
JRuby Environment
=================
JRuby executable:
/Users/headius/projects/jruby/bin/jruby.bash
JRuby command line options:
--environment --dev
Environment:
@headius
headius / gist:571cf242714b95f690e059b999088feb
Last active Sep 18, 2019
JRuby -e startup times on JDK8 and JDK13
View gist:571cf242714b95f690e059b999088feb
$ pickjdk 4 ; time jruby -e 1
New JDK: jdk-08-u202-b08-hotspot
real 0m1.601s
user 0m4.434s
sys 0m0.234s
$ pickjdk 4 ; time jruby --dev -e 1
New JDK: jdk-08-u202-b08-hotspot
View gist:ddea3e163d661be3fe980e78daa811ca
[] ~/projects/jruby $ pickjdk
1) adoptopenjdk-12.jdk
2) graalvm-ee-19.1.0
3) jdk-08-u202-b08-hotspot
4) jdk-08-u222-b10-openj9.jdk
5) jdk-09.0.4.jdk
6) jdk-10.0.1.jdk
7) jdk-11.0.2+9-hotspot
8) jdk-11.0.2+9_openj9-0.12.1
9) labsjdk1.8.0_172-jvmci-0.46
@headius
headius / foo.diff
Created Aug 9, 2019
Pooled object array for interpreter
View foo.diff
diff --git a/core/src/main/java/org/jruby/ir/instructions/AliasInstr.java b/core/src/main/java/org/jruby/ir/instructions/AliasInstr.java
index ef1c033c63..afcca68f54 100644
--- a/core/src/main/java/org/jruby/ir/instructions/AliasInstr.java
+++ b/core/src/main/java/org/jruby/ir/instructions/AliasInstr.java
@@ -44,9 +44,9 @@ public class AliasInstr extends TwoOperandInstr implements FixedArityInstr {
}
@Override
- public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) {
- IRubyObject newName = (IRubyObject) getNewName().retrieve(context, self, currScope, currDynScope, temp);
View gist:467a12f8cfc1ae2195060008185fbd0a
diff --git a/core/src/main/java/org/jruby/javasupport/JavaUtil.java b/core/src/main/java/org/jruby/javasupport/JavaUtil.java
index 85e6e4acbd..05935c5bde 100644
--- a/core/src/main/java/org/jruby/javasupport/JavaUtil.java
+++ b/core/src/main/java/org/jruby/javasupport/JavaUtil.java
@@ -59,6 +59,8 @@ import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+
+import org.jruby.MetaClass;
View 1.trivial deep method chain.rb
def foo1; foo2; end
def foo2; foo3; end
def foo3; foo4; end
def foo4; foo5; end
def foo5; foo6; end
def foo6; foo7; end
def foo7; foo8; end
def foo8; foo9; end
def foo9; self; end
loop { foo1 }
You can’t perform that action at this time.