Skip to content

Commit

Permalink
Showing 50 changed files with 695 additions and 690 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9.1.0.0
9.1.0.0-SNAPSHOT
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ DO NOT MODIFIY - GENERATED CODE
<parent>
<groupId>org.jruby</groupId>
<artifactId>jruby-parent</artifactId>
<version>9.1.0.0</version>
<version>9.1.0.0-SNAPSHOT</version>
</parent>
<artifactId>jruby-core</artifactId>
<name>JRuby Core</name>
35 changes: 35 additions & 0 deletions core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
Original file line number Diff line number Diff line change
@@ -47,6 +47,7 @@
import java.io.IOException;
import java.lang.invoke.MethodHandle;
import java.util.Arrays;
import java.util.Map;

public class IRRuntimeHelpers {
private static final Logger LOG = LoggerFactory.getLogger("IRRuntimeHelpers");
@@ -1858,4 +1859,38 @@ public static IRubyObject callOptimizedAref(ThreadContext context, IRubyObject c

return site.call(context, caller, target, keyStr.strDup(context.runtime));
}

public static DynamicMethod getRefinedMethod(ThreadContext context, RubyClass selfType, String methodName) {
StaticScope refinedScope = context.getCurrentStaticScope();
Map<RubyClass, RubyModule> refinements;
RubyModule refinement;
DynamicMethod method = null;

while (true) {
if (refinedScope == null) break;

refinements = refinedScope.getOverlayModule(context).getRefinements();

if (!refinements.isEmpty()) {

for (Map.Entry<RubyClass, RubyModule> refinementEntry : refinements.entrySet()) {

if (selfType.isKindOfModule(refinementEntry.getKey())) {

refinement = refinementEntry.getValue();
method = refinement.searchMethod(methodName);

if (!method.isUndefined()) {
break;
}

method = null;
}
}
}

refinedScope = refinedScope.getEnclosingScope();
}
return method;
}
}
Original file line number Diff line number Diff line change
@@ -414,7 +414,7 @@ protected IRubyObject callMethodMissing(ThreadContext context, IRubyObject self,

protected abstract boolean methodMissing(DynamicMethod method, IRubyObject caller);

private static RubyClass getClass(IRubyObject self) {
protected static RubyClass getClass(IRubyObject self) {
// the cast in the following line is necessary due to lacking optimizations in Hotspot
return ((RubyBasicObject) self).getMetaClass();
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
package org.jruby.runtime.callsite;

import org.jruby.RubyBasicObject;
import org.jruby.RubyClass;
import org.jruby.RubyFixnum;
import org.jruby.RubyFloat;
import org.jruby.RubyModule;
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.internal.runtime.methods.UndefinedMethod;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Block;
import org.jruby.runtime.CallSite;
import org.jruby.runtime.CallType;
import org.jruby.runtime.ClassIndex;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

@@ -26,21 +20,9 @@ public RefinedCachingCallSite(String methodName, CallType callType) {
@Override
public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject... args) {
RubyClass selfType = getClass(self);
StaticScope refinedScope = context.getCurrentStaticScope();
Map<RubyClass, RubyModule> refinements;
RubyModule refinement;
DynamicMethod method = null;

while (refinedScope != null &&
(
(refinements = refinedScope.getOverlayModule(context).getRefinements()).isEmpty() ||
(refinement = refinements.get(selfType)) == null ||
(method = refinement.searchMethod(methodName)).isUndefined())
) {
refinedScope = refinedScope.getPreviousCRefScope();
}
DynamicMethod method = IRRuntimeHelpers.getRefinedMethod(context, selfType, methodName);

if (refinedScope == null) {
if (method == null) {
return super.call(context, caller, self, args);
}

@@ -49,44 +31,20 @@ public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject s

public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject[] args, Block block) {
RubyClass selfType = getClass(self);
StaticScope refinedScope = context.getCurrentStaticScope();
Map<RubyClass, RubyModule> refinements;
RubyModule refinement;
DynamicMethod method = null;

while (refinedScope != null &&
(
(refinements = refinedScope.getOverlayModule(context).getRefinements()).isEmpty() ||
(refinement = refinements.get(selfType)) == null ||
(method = refinement.searchMethod(methodName)).isUndefined())
) {
refinedScope = refinedScope.getPreviousCRefScope();
}
DynamicMethod method = IRRuntimeHelpers.getRefinedMethod(context, selfType, methodName);

if (refinedScope == null) {
return super.call(context, caller, self);
if (method == null) {
return super.call(context, caller, self, args, block);
}

return method.call(context, self, selfType, methodName, args, block);
}

public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self) {
RubyClass selfType = getClass(self);
StaticScope refinedScope = context.getCurrentStaticScope();
Map<RubyClass, RubyModule> refinements;
RubyModule refinement;
DynamicMethod method = null;

while (refinedScope != null &&
(
(refinements = refinedScope.getOverlayModule(context).getRefinements()).isEmpty() ||
(refinement = refinements.get(selfType)) == null ||
(method = refinement.searchMethod(methodName)).isUndefined())
) {
refinedScope = refinedScope.getPreviousCRefScope();
}
DynamicMethod method = IRRuntimeHelpers.getRefinedMethod(context, selfType, methodName);

if (refinedScope == null) {
if (method == null) {
return super.call(context, caller, self);
}

@@ -95,21 +53,9 @@ public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject s

public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, Block block) {
RubyClass selfType = getClass(self);
StaticScope refinedScope = context.getCurrentStaticScope();
Map<RubyClass, RubyModule> refinements;
RubyModule refinement;
DynamicMethod method = null;

while (refinedScope != null &&
(
(refinements = refinedScope.getOverlayModule(context).getRefinements()).isEmpty() ||
(refinement = refinements.get(selfType)) == null ||
(method = refinement.searchMethod(methodName)).isUndefined())
) {
refinedScope = refinedScope.getPreviousCRefScope();
}
DynamicMethod method = IRRuntimeHelpers.getRefinedMethod(context, selfType, methodName);

if (refinedScope == null) {
if (method == null) {
return super.call(context, caller, self, block);
}

@@ -118,21 +64,9 @@ public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject s

public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject arg0) {
RubyClass selfType = getClass(self);
StaticScope refinedScope = context.getCurrentStaticScope();
Map<RubyClass, RubyModule> refinements;
RubyModule refinement;
DynamicMethod method = null;

while (refinedScope != null &&
(
(refinements = refinedScope.getOverlayModule(context).getRefinements()).isEmpty() ||
(refinement = refinements.get(selfType)) == null ||
(method = refinement.searchMethod(methodName)).isUndefined())
) {
refinedScope = refinedScope.getPreviousCRefScope();
}
DynamicMethod method = IRRuntimeHelpers.getRefinedMethod(context, selfType, methodName);

if (refinedScope == null) {
if (method == null) {
return super.call(context, caller, self, arg0);
}

@@ -141,21 +75,9 @@ public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject s

public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject arg0, Block block) {
RubyClass selfType = getClass(self);
StaticScope refinedScope = context.getCurrentStaticScope();
Map<RubyClass, RubyModule> refinements;
RubyModule refinement;
DynamicMethod method = null;

while (refinedScope != null &&
(
(refinements = refinedScope.getOverlayModule(context).getRefinements()).isEmpty() ||
(refinement = refinements.get(selfType)) == null ||
(method = refinement.searchMethod(methodName)).isUndefined())
) {
refinedScope = refinedScope.getPreviousCRefScope();
}
DynamicMethod method = IRRuntimeHelpers.getRefinedMethod(context, selfType, methodName);

if (refinedScope == null) {
if (method == null) {
return super.call(context, caller, self, arg0, block);
}

@@ -164,44 +86,20 @@ public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject s

public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject arg0, IRubyObject arg1) {
RubyClass selfType = getClass(self);
StaticScope refinedScope = context.getCurrentStaticScope();
Map<RubyClass, RubyModule> refinements;
RubyModule refinement;
DynamicMethod method = null;

while (refinedScope != null &&
(
(refinements = refinedScope.getOverlayModule(context).getRefinements()).isEmpty() ||
(refinement = refinements.get(selfType)) == null ||
(method = refinement.searchMethod(methodName)).isUndefined())
) {
refinedScope = refinedScope.getPreviousCRefScope();
}
DynamicMethod method = IRRuntimeHelpers.getRefinedMethod(context, selfType, methodName);

if (refinedScope == null) {
if (method == null) {
return super.call(context, caller, self, arg0, arg1);
}

return method.call(context, self, selfType, methodName);
return method.call(context, self, selfType, methodName, arg0, arg1);
}

public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject arg0, IRubyObject arg1, Block block) {
RubyClass selfType = getClass(self);
StaticScope refinedScope = context.getCurrentStaticScope();
Map<RubyClass, RubyModule> refinements;
RubyModule refinement;
DynamicMethod method = null;

while (refinedScope != null &&
(
(refinements = refinedScope.getOverlayModule(context).getRefinements()).isEmpty() ||
(refinement = refinements.get(selfType)) == null ||
(method = refinement.searchMethod(methodName)).isUndefined())
) {
refinedScope = refinedScope.getPreviousCRefScope();
}
DynamicMethod method = IRRuntimeHelpers.getRefinedMethod(context, selfType, methodName);

if (refinedScope == null) {
if (method == null) {
return super.call(context, caller, self, arg0, arg1, block);
}

@@ -210,21 +108,9 @@ public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject s

public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
RubyClass selfType = getClass(self);
StaticScope refinedScope = context.getCurrentStaticScope();
Map<RubyClass, RubyModule> refinements;
RubyModule refinement;
DynamicMethod method = null;

while (refinedScope != null &&
(
(refinements = refinedScope.getOverlayModule(context).getRefinements()).isEmpty() ||
(refinement = refinements.get(selfType)) == null ||
(method = refinement.searchMethod(methodName)).isUndefined())
) {
refinedScope = refinedScope.getPreviousCRefScope();
}
DynamicMethod method = IRRuntimeHelpers.getRefinedMethod(context, selfType, methodName);

if (refinedScope == null) {
if (method == null) {
return super.call(context, caller, self, arg0, arg1, arg2);
}

@@ -233,21 +119,9 @@ public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject s

public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
RubyClass selfType = getClass(self);
StaticScope refinedScope = context.getCurrentStaticScope();
Map<RubyClass, RubyModule> refinements;
RubyModule refinement;
DynamicMethod method = null;

while (refinedScope != null &&
(
(refinements = refinedScope.getOverlayModule(context).getRefinements()).isEmpty() ||
(refinement = refinements.get(selfType)) == null ||
(method = refinement.searchMethod(methodName)).isUndefined())
) {
refinedScope = refinedScope.getPreviousCRefScope();
}
DynamicMethod method = IRRuntimeHelpers.getRefinedMethod(context, selfType, methodName);

if (refinedScope == null) {
if (method == null) {
return super.call(context, caller, self, arg0, arg1, arg2, block);
}

@@ -258,9 +132,4 @@ protected boolean methodMissing(DynamicMethod method, IRubyObject caller) {
// doing full "normal" MM check rather than multiple refined sites by call types
return method.isUndefined() || (!methodName.equals("method_missing") && !method.isCallableFrom(caller, callType));
}

private static RubyClass getClass(IRubyObject self) {
// the cast in the following line is necessary due to lacking optimizations in Hotspot
return ((RubyBasicObject) self).getMetaClass();
}
}
14 changes: 10 additions & 4 deletions core/src/main/java/org/jruby/util/Numeric.java
Original file line number Diff line number Diff line change
@@ -507,19 +507,25 @@ public static IRubyObject int_pow(ThreadContext context, long x, long y) {
y >>= 1;
}

BigInteger bigX = BigInteger.valueOf(x);
BigInteger bigXZ = bigX.multiply(bigX);
if (bigXZ.divide(bigX).longValue() != z) {
if (multiplyOverflows(x, z)) {
IRubyObject v = RubyBignum.newBignum(runtime, RubyBignum.fix2big(RubyFixnum.newFixnum(runtime, x))).op_pow(context, RubyFixnum.newFixnum(runtime, y));
if (z != 1) v = RubyBignum.newBignum(runtime, RubyBignum.fix2big(RubyFixnum.newFixnum(runtime, neg ? -z : z))).op_mul19(context, v);
return v;
}
z = bigXZ.longValue();
z = x * z;
} while(--y != 0);
if (neg) z = -z;
return RubyFixnum.newFixnum(runtime, z);
}

public static boolean multiplyOverflows(long a, long b) {
return a == 0 ? false :
a == -1 ? b < -Long.MAX_VALUE :
a > 0 ? (b > 0 ? Long.MAX_VALUE / a < b : Long.MIN_VALUE / a > b) :
(b > 0 ? Long.MIN_VALUE / a < b : Long.MAX_VALUE / a > b);
}


public static boolean k_exact_p(IRubyObject x) {
return !(x instanceof RubyFloat);
}
4 changes: 2 additions & 2 deletions lib/pom.xml
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ DO NOT MODIFIY - GENERATED CODE
<parent>
<groupId>org.jruby</groupId>
<artifactId>jruby-parent</artifactId>
<version>9.1.0.0</version>
<version>9.1.0.0-SNAPSHOT</version>
</parent>
<artifactId>jruby-stdlib</artifactId>
<name>JRuby Lib Setup</name>
@@ -28,7 +28,7 @@ DO NOT MODIFIY - GENERATED CODE
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby-core</artifactId>
<version>9.1.0.0</version>
<version>9.1.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
Original file line number Diff line number Diff line change
@@ -166,3 +166,5 @@
- rubygems
- shims
- openssl-stubs
:environment:
N: 1
Loading

0 comments on commit 3e5ecb3

Please sign in to comment.