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

Commits on Apr 17, 2018

  1. Copy the full SHA
    f248488 View commit details
  2. Merge branch 'jruby-9.1'

    headius committed Apr 17, 2018

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    0a84dc7 View commit details
  3. Copy the full SHA
    95a41f9 View commit details
14 changes: 1 addition & 13 deletions core/src/main/java/org/jruby/RubyThread.java
Original file line number Diff line number Diff line change
@@ -648,20 +648,8 @@ private static void initThreadName(final Ruby runtime, final Thread thread, fina
thread.setName(newName);
}

// TODO likely makes sense to have a counter or the Ruby class directly (could be included with JMX)
private static final WeakHashMap<Ruby, AtomicLong> threadCount = new WeakHashMap<Ruby, AtomicLong>(4);

private static long incAndGetThreadCount(final Ruby runtime) {
AtomicLong counter = threadCount.get(runtime);
if ( counter == null ) {
synchronized (runtime) {
counter = threadCount.get(runtime);
if ( counter == null ) {
threadCount.put(runtime, counter = new AtomicLong(0));
}
}
}
return counter.incrementAndGet();
return runtime.getThreadService().incrementAndGetThreadCount();
}

private static RubyThread startThread(final IRubyObject recv, final IRubyObject[] args, boolean callInit, Block block) {
7 changes: 6 additions & 1 deletion core/src/main/java/org/jruby/ext/date/DateUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jruby.ext.date;

import org.jruby.*;
import org.jruby.runtime.JavaSites;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

@@ -230,7 +231,7 @@ static int offset_to_sec(ThreadContext context, IRubyObject of) {
//if (d != n) rb_warning("fraction of offset is ignored");
return (int) n;
case STRING:
vs = date_zone_to_diff(context, (RubyString) of);
vs = sites(context).zone_to_diff.call(context, of, of);

if (!(vs instanceof RubyFixnum)) return INVALID_OFFSET;
n = ((RubyFixnum) vs).getLongValue();
@@ -439,6 +440,10 @@ else if (iy > REFORM_END_YEAR)
return style;
}

private static JavaSites.DateSites sites(ThreadContext context) {
return context.sites.Date;
}

private static final int JC_PERIOD0 = 1461; /* 365.25 * 4 */
private static final int GC_PERIOD0 = 146097; /* 365.2425 * 400 */
private static final int CM_PERIOD0 = 71149239; /* (lcm 7 1461 146097) */
11 changes: 2 additions & 9 deletions core/src/main/java/org/jruby/ext/date/RubyDate.java
Original file line number Diff line number Diff line change
@@ -234,7 +234,7 @@ private void initialize(final ThreadContext context, IRubyObject arg, IRubyObjec

static final int DAY_IN_SECONDS = 86_400; // 24 * 60 * 60
static final int DAY_MS = 86_400_000; // 24 * 60 * 60 * 1000
private static RubyFixnum DAY_MS_CACHE;
private RubyFixnum DAY_MS_CACHE;

private long initMillis(final ThreadContext context, IRubyObject ajd) {
final Ruby runtime = context.runtime;
@@ -272,7 +272,7 @@ private long initMillis(final ThreadContext context, IRubyObject ajd) {
return ((RubyFixnum) millis).getLongValue();
}

private static RubyFixnum DAY_MS(final ThreadContext context) {
private RubyFixnum DAY_MS(final ThreadContext context) {
RubyFixnum v = DAY_MS_CACHE;
if (v == null) v = DAY_MS_CACHE = context.runtime.newFixnum(DAY_MS);
return v;
@@ -1394,13 +1394,6 @@ static RubyRational newRationalConvert(ThreadContext context, IRubyObject num, l
return (RubyRational) RubyRational.newRationalConvert(context, num, context.runtime.newFixnum(den));
}

private static final CachingCallSite zone_to_diff = new FunctionalCachingCallSite("zone_to_diff");

static IRubyObject date_zone_to_diff(final ThreadContext context, RubyString str) {
final RubyClass klass = getDate(context.runtime);
return zone_to_diff.call(context, klass, klass, str);
}

// def jd_to_ajd(jd, fr, of=0) jd + fr - of - Rational(1, 2) end
private static double jd_to_ajd(long jd) { return jd - 0.5; }

Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@
package org.jruby.internal.runtime;

import java.lang.ref.SoftReference;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.ReentrantLock;

import java.util.ArrayList;
@@ -139,6 +140,8 @@ public class ThreadService {

private final ReentrantLock criticalLock = new ReentrantLock();

private final AtomicLong threadCount = new AtomicLong(0);

public ThreadService(final Ruby runtime) {
this.runtime = runtime;
this.localContext = new ThreadLocal<SoftReference<ThreadContext>>();
@@ -293,6 +296,10 @@ public boolean getCritical() {
return criticalLock.isHeldByCurrentThread();
}

public long incrementAndGetThreadCount() {
return threadCount.incrementAndGet();
}

@Deprecated
public Map<Object, RubyThread> getRubyThreadMap() {
return rubyThreadMap;
5 changes: 5 additions & 0 deletions core/src/main/java/org/jruby/runtime/JavaSites.java
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@ public class JavaSites {
public final TracePointSites TracePoint = new TracePointSites();
public final MarshalSites Marshal = new MarshalSites();
public final PathnameSites Pathname = new PathnameSites();
public final DateSites Date = new DateSites();

public static class BasicObjectSites {
public final CallSite respond_to = new FunctionalCachingCallSite("respond_to?");
@@ -453,6 +454,10 @@ public static class PathnameSites {
public final CallSite op_plus = new FunctionalCachingCallSite("+");
}

public static class DateSites {
public final CallSite zone_to_diff = new FunctionalCachingCallSite("zone_to_diff");
}

public static class CheckedSites {
public final RespondToCallSite respond_to_X;
public final CachingCallSite respond_to_missing = new FunctionalCachingCallSite("respond_to_missing?");
8 changes: 3 additions & 5 deletions core/src/main/java/org/jruby/util/IOInputStream.java
Original file line number Diff line number Diff line change
@@ -50,13 +50,11 @@
* that it responds to read() like IO.
*/
public class IOInputStream extends InputStream {

private static final CallSite readAdapter = MethodIndex.getFunctionalCallSite("read");
private static final CallSite closeAdapter = MethodIndex.getFunctionalCallSite("close");

private final IRubyObject io;
private final InputStream in;
private final RubyFixnum numOne;
private final IRubyObject numOne;
private final CallSite readAdapter = MethodIndex.getFunctionalCallSite("read");
private final CallSite closeAdapter = MethodIndex.getFunctionalCallSite("close");

/**
* Creates a new InputStream with the object provided.
4 changes: 1 addition & 3 deletions core/src/main/java/org/jruby/util/IOOutputStream.java
Original file line number Diff line number Diff line change
@@ -51,12 +51,10 @@
* @author <a href="mailto:Ola.Bini@ki.se">Ola Bini</a>
*/
public class IOOutputStream extends OutputStream {

private static final CallSite closeAdapter = MethodIndex.getFunctionalCallSite("close");

private final IRubyObject io;
private final OutputStream out;
private final CallSite writeAdapter;
private final CallSite closeAdapter = MethodIndex.getFunctionalCallSite("close");
private final Encoding encoding;

/**