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: eb33d8979a8e
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 050b8220590c
Choose a head ref
  • 10 commits
  • 10 files changed
  • 1 contributor

Commits on Jun 17, 2016

  1. Copy the full SHA
    3856dfb View commit details
  2. make getClassRuntime final

    kares committed Jun 17, 2016
    Copy the full SHA
    e3ba026 View commit details
  3. [ji] make __jcreate! call site lazy since it won't be needed most of …

    …time
    
    ... only for minor cases when Java sub-class' initialize does not call super
    kares committed Jun 17, 2016
    Copy the full SHA
    7f7326c View commit details
  4. still some double (caching) call-site count++ going on

    ... in NormalCachingCallSite/VariableCachingCallSite
    kares committed Jun 17, 2016
    Copy the full SHA
    99b7fe9 View commit details
  5. make Sockaddr.unpack_sockaddr_in return a RubyArray

    ... like it always does
    kares committed Jun 17, 2016
    Copy the full SHA
    83aeb87 View commit details
  6. cleanup and extract RubyArray (arg) internals directly

    ... avoiding RubyArray#getList + refactor to use getIntValue
    kares committed Jun 17, 2016
    Copy the full SHA
    9638257 View commit details
  7. cleanup dead-code - unpack_sockaddr_in returns RubyArray

    ... also extract array elements directly (avoid RubyArray#getList)
    kares committed Jun 17, 2016
    Copy the full SHA
    aa343ba View commit details
  8. Copy the full SHA
    c5a91f3 View commit details
  9. deprecate RubyArray#getList (code-base no longer using it)

    ... dates back the days when RubyArray did not impement List
    kares committed Jun 17, 2016
    Copy the full SHA
    45d65e6 View commit details
  10. Copy the full SHA
    050b822 View commit details
7 changes: 4 additions & 3 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -408,10 +408,11 @@ private static final void checkLength(Ruby runtime, long length) {
}
}

/** Getter for property list.
* @return Value of property list.
/**
* @deprecated RubyArray implements List, use it directly
* @return a read-only copy of this list
*/
public List getList() {
public final List<IRubyObject> getList() {
return Arrays.asList(toJavaArray());
}

2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyClass.java
Original file line number Diff line number Diff line change
@@ -1091,7 +1091,7 @@ public void addInvalidatorsAndFlush(List<Invalidator> invalidators) {
}
}

public Ruby getClassRuntime() {
public final Ruby getClassRuntime() {
return runtime;
}

10 changes: 4 additions & 6 deletions core/src/main/java/org/jruby/RubySymbol.java
Original file line number Diff line number Diff line change
@@ -42,19 +42,18 @@
import org.jruby.anno.JRubyMethod;
import org.jruby.ast.util.ArgsUtil;
import org.jruby.compiler.Constantizable;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.ArgumentDescriptor;
import org.jruby.runtime.Binding;
import org.jruby.runtime.Block;
import org.jruby.runtime.BlockBody;
import org.jruby.runtime.CallSite;
import org.jruby.runtime.ClassIndex;
import org.jruby.runtime.ContextAwareBlockBody;
import org.jruby.runtime.MethodIndex;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.Signature;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.callsite.FunctionalCachingCallSite;
import org.jruby.runtime.encoding.EncodingCapable;
import org.jruby.runtime.encoding.MarshalEncoding;
import org.jruby.runtime.marshal.UnmarshalStream;
@@ -1025,21 +1024,20 @@ public static String objectToSymbolString(IRubyObject object) {
return object.convertToString().getByteList().toString();
}

private static class SymbolProcBody extends ContextAwareBlockBody {
private static final class SymbolProcBody extends ContextAwareBlockBody {
private final CallSite site;

public SymbolProcBody(Ruby runtime, String symbol) {
super(runtime.getStaticScopeFactory().getDummyScope(), Signature.OPTIONAL);
this.site = new FunctionalCachingCallSite(symbol);
this.site = MethodIndex.getFunctionalCallSite(symbol);
}

private IRubyObject yieldInner(ThreadContext context, RubyArray array, Block blockArg) {
if (array.isEmpty()) {
throw context.runtime.newArgumentError("no receiver given");
}

IRubyObject self = array.shift(context);

final IRubyObject self = array.shift(context);
return site.call(context, self, self, array.toJavaArray(), blockArg);
}

35 changes: 13 additions & 22 deletions core/src/main/java/org/jruby/ext/socket/SocketUtils.java
Original file line number Diff line number Diff line change
@@ -143,7 +143,7 @@ public static IRubyObject pack_sockaddr_in(ThreadContext context, IRubyObject po
return Sockaddr.pack_sockaddr_in(context, portNum, hostStr);
}

public static IRubyObject unpack_sockaddr_in(ThreadContext context, IRubyObject addr) {
public static RubyArray unpack_sockaddr_in(ThreadContext context, IRubyObject addr) {
return Sockaddr.unpack_sockaddr_in(context, addr);
}

@@ -380,40 +380,31 @@ public static IRubyObject getnameinfo(ThreadContext context, IRubyObject[] args)
String host, port;

if (arg0 instanceof RubyArray) {
List list = ((RubyArray)arg0).getList();
int len = list.size();
RubyArray ary = (RubyArray) arg0;
final int len = ary.size();

if (len < 3 || len > 4) {
throw runtime.newArgumentError("array size should be 3 or 4, "+len+" given");
throw runtime.newArgumentError("array size should be 3 or 4, "+ len +" given");
}

// if array has 4 elements, third element is ignored
host = list.size() == 3 ? list.get(2).toString() : list.get(3).toString();
port = list.get(1).toString();
port = ary.eltInternal(1).toString();
host = len == 3 ? ary.eltInternal(2).toString() : ary.eltInternal(3).toString();

} else if (arg0 instanceof RubyString) {
String arg = ((RubyString)arg0).toString();
String arg = ((RubyString) arg0).toString();
Matcher m = STRING_IPV4_ADDRESS_PATTERN.matcher(arg);

if (!m.matches()) {
IRubyObject obj = unpack_sockaddr_in(context, arg0);

if (obj instanceof RubyArray) {
List list = ((RubyArray)obj).getList();
int len = list.size();

if (len != 2) {
throw runtime.newArgumentError("invalid address representation");
}

host = list.get(1).toString();
port = list.get(0).toString();

} else {
throw runtime.newArgumentError("invalid address string");
RubyArray portAndHost = unpack_sockaddr_in(context, arg0);

if (portAndHost.size() != 2) {
throw runtime.newArgumentError("invalid address representation");
}

port = portAndHost.eltInternal(0).toString();
host = portAndHost.eltInternal(1).toString();

} else if ((host = m.group(IPV4_HOST_GROUP)) == null || host.length() == 0 ||
(port = m.group(IPV4_PORT_GROUP)) == null || port.length() == 0) {

31 changes: 17 additions & 14 deletions core/src/main/java/org/jruby/java/proxies/ConcreteJavaProxy.java
Original file line number Diff line number Diff line change
@@ -88,86 +88,89 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz

private static final class NewMethod extends org.jruby.internal.runtime.methods.JavaMethod {

private final CallSite jcreateSite = MethodIndex.getFunctionalCallSite("__jcreate!");
private transient CallSite jcreateSite;
final DynamicMethod newMethod;

NewMethod(final RubyClass clazz) {
super(clazz, Visibility.PUBLIC);
newMethod = clazz.searchMethod("new");
}

private static boolean needsCreate(IRubyObject proxy) {
return ((JavaProxy) proxy).object == null;
private CallSite jcreateSite() { // most of the time we won't need to instantiate
CallSite callSite = jcreateSite;
if (callSite == null) {
callSite = jcreateSite = MethodIndex.getFunctionalCallSite("__jcreate!");
}
return callSite;
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
IRubyObject proxy = newMethod.call(context, self, clazz, "new_proxy", args, block);
if (needsCreate(proxy)) jcreateSite.call(context, proxy, proxy, args, block);
if ( ((JavaProxy) proxy).object == null ) jcreateSite().call(context, proxy, proxy, args, block);
return proxy;
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, Block block) {
IRubyObject proxy = newMethod.call(context, self, clazz, "new_proxy", block);
if (needsCreate(proxy)) jcreateSite.call(context, proxy, proxy, block);
if ( ((JavaProxy) proxy).object == null ) jcreateSite().call(context, proxy, proxy, block);
return proxy;
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, Block block) {
IRubyObject proxy = newMethod.call(context, self, clazz, "new_proxy", arg0, block);
if (needsCreate(proxy)) jcreateSite.call(context, proxy, proxy, arg0, block);

if ( ((JavaProxy) proxy).object == null ) jcreateSite().call(context, proxy, proxy, arg0, block);
return proxy;
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, Block block) {
IRubyObject proxy = newMethod.call(context, self, clazz, "new_proxy", arg0, arg1, block);
if (needsCreate(proxy)) jcreateSite.call(context, proxy, proxy, arg0, arg1, block);
if ( ((JavaProxy) proxy).object == null ) jcreateSite().call(context, proxy, proxy, arg0, arg1, block);
return proxy;
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
IRubyObject proxy = newMethod.call(context, self, clazz, "new_proxy", arg0, arg1, arg2, block);
if (needsCreate(proxy)) jcreateSite.call(context, proxy, proxy, arg0, arg1, arg2, block);
if ( ((JavaProxy) proxy).object == null ) jcreateSite().call(context, proxy, proxy, arg0, arg1, arg2, block);
return proxy;
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
IRubyObject proxy = newMethod.call(context, self, clazz, "new_proxy", args);
if (needsCreate(proxy)) jcreateSite.call(context, proxy, proxy, args);
if ( ((JavaProxy) proxy).object == null ) jcreateSite().call(context, proxy, proxy, args);
return proxy;
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name) {
IRubyObject proxy = newMethod.call(context, self, clazz, "new_proxy");
if (needsCreate(proxy)) jcreateSite.call(context, proxy, proxy);
if ( ((JavaProxy) proxy).object == null ) jcreateSite().call(context, proxy, proxy);
return proxy;
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0) {
IRubyObject proxy = newMethod.call(context, self, clazz, "new_proxy", arg0);
if (needsCreate(proxy)) jcreateSite.call(context, proxy, proxy, arg0);
if ( ((JavaProxy) proxy).object == null ) jcreateSite().call(context, proxy, proxy, arg0);
return proxy;
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1) {
IRubyObject proxy = newMethod.call(context, self, clazz, "new_proxy", arg0, arg1);
if (needsCreate(proxy)) jcreateSite.call(context, proxy, proxy, arg0, arg1);
if ( ((JavaProxy) proxy).object == null ) jcreateSite().call(context, proxy, proxy, arg0, arg1);
return proxy;
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
IRubyObject proxy = newMethod.call(context, self, clazz, "new_proxy", arg0, arg1, arg2);
if (needsCreate(proxy)) jcreateSite.call(context, proxy, proxy, arg0, arg1, arg2);
if ( ((JavaProxy) proxy).object == null ) jcreateSite().call(context, proxy, proxy, arg0, arg1, arg2);
return proxy;
}

26 changes: 13 additions & 13 deletions core/src/main/java/org/jruby/javasupport/JavaClass.java
Original file line number Diff line number Diff line change
@@ -718,29 +718,29 @@ public JavaClass array_class() {
public JavaObject new_array(IRubyObject lengthArgument) {
if (lengthArgument instanceof RubyInteger) {
// one-dimensional array
int length = (int) ((RubyInteger) lengthArgument).getLongValue();
int length = ((RubyInteger) lengthArgument).getIntValue();
return new JavaArray(getRuntime(), Array.newInstance(javaClass(), length));
} else if (lengthArgument instanceof RubyArray) {
}
else if (lengthArgument instanceof RubyArray) {
// n-dimensional array
List list = ((RubyArray)lengthArgument).getList();
int length = list.size();
IRubyObject[] aryLengths = ((RubyArray)lengthArgument).toJavaArrayMaybeUnsafe();
final int length = aryLengths.length;
if (length == 0) {
throw getRuntime().newArgumentError("empty dimensions specifier for java array");
}
int[] dimensions = new int[length];
final int[] dimensions = new int[length];
for (int i = length; --i >= 0; ) {
IRubyObject dimensionLength = (IRubyObject)list.get(i);
if ( !(dimensionLength instanceof RubyInteger) ) {
throw getRuntime()
.newTypeError(dimensionLength, getRuntime().getInteger());
IRubyObject dimLength = aryLengths[i];
if ( ! ( dimLength instanceof RubyInteger ) ) {
throw getRuntime().newTypeError(dimLength, getRuntime().getInteger());
}
dimensions[i] = (int) ((RubyInteger) dimensionLength).getLongValue();
dimensions[i] = ((RubyInteger) dimLength).getIntValue();
}
return new JavaArray(getRuntime(), Array.newInstance(javaClass(), dimensions));
} else {
}
else {
throw getRuntime().newArgumentError(
"invalid length or dimensions specifier for java array" +
" - must be Integer or Array of Integer");
"invalid length or dimensions specifier for java array - must be Integer or Array of Integer");
}
}

Original file line number Diff line number Diff line change
@@ -5,9 +5,9 @@
import org.jruby.runtime.builtin.IRubyObject;

public class FunctionalCachingCallSite extends CachingCallSite {

public FunctionalCachingCallSite(String methodName) {
super(methodName, CallType.FUNCTIONAL);
totalCallSites++;
}

protected boolean methodMissing(DynamicMethod method, IRubyObject caller) {
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@
public class NormalCachingCallSite extends CachingCallSite {
public NormalCachingCallSite(String methodName) {
super(methodName, CallType.NORMAL);
totalCallSites++;
}

protected boolean methodMissing(DynamicMethod method, IRubyObject caller) {
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@
public class VariableCachingCallSite extends CachingCallSite {
public VariableCachingCallSite(String methodName) {
super(methodName, CallType.VARIABLE);
totalCallSites++;
}

protected boolean methodMissing(DynamicMethod method, IRubyObject caller) {
32 changes: 13 additions & 19 deletions core/src/main/java/org/jruby/util/io/Sockaddr.java
Original file line number Diff line number Diff line change
@@ -80,8 +80,8 @@ public static UnixSocketAddress addressFromSockaddr_un(ThreadContext context, IR
return new UnixSocketAddress(new File(pathStr));
}

public static IRubyObject unpack_sockaddr_in(ThreadContext context, IRubyObject addr) {
Ruby runtime = context.runtime;
public static RubyArray unpack_sockaddr_in(ThreadContext context, IRubyObject addr) {
final Ruby runtime = context.runtime;
ByteList val = addr.convertToString().getByteList();

validateSockaddr(runtime, val);
@@ -90,31 +90,25 @@ public static IRubyObject unpack_sockaddr_in(ThreadContext context, IRubyObject

AddressFamily af = getAddressFamilyFromSockaddr(runtime, val);

StringBuilder sb = new StringBuilder();
final StringBuilder formatAddr = new StringBuilder();

if (af == AddressFamily.AF_INET) {
sb.append(val.get(4) & 0xff)
.append(".")
.append(val.get(5) & 0xff)
.append(".")
.append(val.get(6) & 0xff)
.append(".")
.append(val.get(7) & 0xff);
formatAddr.append(val.get(4) & 0xff)
.append('.')
.append(val.get(5) & 0xff)
.append('.')
.append(val.get(6) & 0xff)
.append('.')
.append(val.get(7) & 0xff);

} else { // if af == AddressFamily.AF_INET6
for (int i = 4; i <= 19; i++) {
if (i != 4 && i % 2 == 0) {
sb.append(":");
}
sb.append(Integer.toHexString(val.get(i) & 0xff | 0x100).substring(1));
if (i != 4 && i % 2 == 0) formatAddr.append(':');
formatAddr.append(Integer.toHexString(val.get(i) & 0xff | 0x100).substring(1));
}
}

IRubyObject[] result = new IRubyObject[]{
runtime.newFixnum(port),
runtime.newString(sb.toString())};

return runtime.newArrayNoCopy(result);
return runtime.newArrayNoCopy(runtime.newFixnum(port), RubyString.newString(runtime, formatAddr));
}

public static IRubyObject packSockaddrFromAddress(ThreadContext context, InetSocketAddress sock) {