Skip to content

Commit

Permalink
Merge branch 'jruby-9.1' into improve_windows_open3
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Feb 13, 2018
2 parents f58ddad + cd56bd7 commit 131ba02
Show file tree
Hide file tree
Showing 103 changed files with 1,510 additions and 928 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ notifications:

services:
- redis-server
- haveged

addons:
apt:
packages:
- oracle-java9-installer
- haveged
2 changes: 1 addition & 1 deletion bin/jruby.bash
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ do
# Match -Xa.b.c=d to translate to -Da.b.c=d as a java option
-X*)
val=${1:2}
if expr "$val" : '.*[.]' > /dev/null; then
if expr -- "$val" : '.*[.]' > /dev/null; then
java_args=("${java_args[@]}" "-Djruby.${val}")
else
ruby_args=("${ruby_args[@]}" "-X${val}")
Expand Down
8 changes: 4 additions & 4 deletions bin/jruby.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ progname=`basename "$0"`

while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '.*/.*' > /dev/null; then
if expr "$link" : '/' > /dev/null; then
link=`expr -- "$ls" : '.*-> \(.*\)$'`
if expr -- "$link" : '.*/.*' > /dev/null; then
if expr -- "$link" : '/' > /dev/null; then
PRG="$link"
else
PRG="`dirname ${PRG}`/${link}"
Expand Down Expand Up @@ -202,7 +202,7 @@ do
# Match -Xa.b.c=d to translate to -Da.b.c=d as a java option
-X*)
val=${1:2}
if expr "$val" : '.*[.]' > /dev/null; then
if expr -- "$val" : '.*[.]' > /dev/null; then
java_args="${java_args} -Djruby.${val}"
else
ruby_args="${ruby_args} -X${val}"
Expand Down
6 changes: 3 additions & 3 deletions core/pom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@
jar 'com.github.jnr:jnr-enxio:0.16', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-x86asm:1.0.2', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-unixsocket:0.17', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-posix:3.0.42', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-posix:3.0.44', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-constants:0.9.9', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-ffi:2.1.7'
jar 'com.github.jnr:jffi:${jffi.version}'
jar 'com.github.jnr:jffi:${jffi.version}:native'

jar 'org.jruby.joni:joni:2.1.13'
jar 'org.jruby.joni:joni:2.1.14'
jar 'org.jruby.extras:bytelist:1.0.15'
jar 'org.jruby.jcodings:jcodings:1.0.18'
jar 'org.jruby.jcodings:jcodings:1.0.27'
jar 'org.jruby:dirgra:0.3'

jar 'com.headius:invokebinder:1.10'
Expand Down
6 changes: 3 additions & 3 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ DO NOT MODIFIY - GENERATED CODE
<dependency>
<groupId>com.github.jnr</groupId>
<artifactId>jnr-posix</artifactId>
<version>3.0.42</version>
<version>3.0.44</version>
<exclusions>
<exclusion>
<artifactId>jnr-ffi</artifactId>
Expand Down Expand Up @@ -173,7 +173,7 @@ DO NOT MODIFIY - GENERATED CODE
<dependency>
<groupId>org.jruby.joni</groupId>
<artifactId>joni</artifactId>
<version>2.1.13</version>
<version>2.1.14</version>
</dependency>
<dependency>
<groupId>org.jruby.extras</groupId>
Expand All @@ -183,7 +183,7 @@ DO NOT MODIFIY - GENERATED CODE
<dependency>
<groupId>org.jruby.jcodings</groupId>
<artifactId>jcodings</artifactId>
<version>1.0.18</version>
<version>1.0.27</version>
</dependency>
<dependency>
<groupId>org.jruby</groupId>
Expand Down
12 changes: 7 additions & 5 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
import org.jruby.parser.StaticScope;
import org.jruby.runtime.JavaSites;
import org.jruby.runtime.invokedynamic.InvokeDynamicSupport;
import org.jruby.runtime.opto.ConstantInvalidator;
import org.jruby.util.MRIRecursionGuard;
import org.jruby.util.io.EncodingUtils;
import org.objectweb.asm.util.TraceClassVisitor;
Expand Down Expand Up @@ -172,8 +171,6 @@
import java.lang.invoke.MethodHandle;
import java.lang.ref.WeakReference;
import java.net.BindException;
import java.net.PortUnreachableException;
import java.nio.channels.ClosedChannelException;
import java.nio.charset.Charset;
import java.security.SecureRandom;
import java.util.ArrayList;
Expand Down Expand Up @@ -1341,7 +1338,7 @@ private void initRoot() {

// In 1.9 and later, Kernel.gsub is defined only when '-p' or '-n' is given on the command line
if (config.getKernelGsubDefined()) {
kernel.addMethod("gsub", new JavaMethod(kernel, Visibility.PRIVATE) {
kernel.addMethod("gsub", new JavaMethod(kernel, Visibility.PRIVATE, "gsub") {

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
Expand Down Expand Up @@ -4580,14 +4577,19 @@ public RubyString freezeAndDedupString(RubyString string) {
RubyString deduped;

if (dedupedRef == null || (deduped = dedupedRef.get()) == null) {
// Never use incoming value as key
deduped = string.strDup(this);
deduped.setFrozen(true);
dedupMap.put(string, new WeakReference<RubyString>(deduped));

// NOTE: This still races because Map.put/computeIfAbsent API is Java 8+.
dedupMap.put(deduped, new WeakReference<>(deduped));
} else if (deduped.getEncoding() != string.getEncoding()) {
// if encodings don't match, new string loses; can't dedup
// FIXME: This may never happen, if we are properly considering encoding in RubyString.hashCode
deduped = string.strDup(this);
deduped.setFrozen(true);
}

return deduped;
}

Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -3311,6 +3311,9 @@ public IRubyObject uniq_bang19(ThreadContext context, Block block) {
RubyHash hash = makeHash(context, block);
if (realLength == hash.size()) return context.runtime.getNil();

// after evaluating the block, a new modify check is needed
modifyCheck();

// TODO: (CON) This could be a no-op for packed arrays if size does not change
unpack();

Expand Down
86 changes: 44 additions & 42 deletions core/src/main/java/org/jruby/RubyClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -1097,19 +1097,27 @@ public final Collection<RubyClass> subclasses() {
return subclasses(false);
}

public synchronized Collection<RubyClass> subclasses(boolean includeDescendants) {
public Collection<RubyClass> subclasses(boolean includeDescendants) {
Set<RubyClass> subclasses = this.subclasses;
if (subclasses != null) {
Collection<RubyClass> mine = new ArrayList<>(subclasses);
Collection<RubyClass> mine = new ArrayList<>();
subclassesInner(mine, includeDescendants);

return mine;
}
return Collections.EMPTY_LIST;
}

private void subclassesInner(Collection<RubyClass> mine, boolean includeDescendants) {
Set<RubyClass> subclasses = this.subclasses;
if (subclasses != null) {
mine.addAll(subclasses);
if (includeDescendants) {
for (RubyClass klass: subclasses) {
mine.addAll(klass.subclasses(includeDescendants));
klass.subclassesInner(mine, includeDescendants);
}
}

return mine;
}
return Collections.EMPTY_LIST;
}

/**
Expand All @@ -1121,26 +1129,31 @@ public synchronized Collection<RubyClass> subclasses(boolean includeDescendants)
*
* @param subclass The subclass to add
*/
public synchronized void addSubclass(RubyClass subclass) {
synchronized (runtime.getHierarchyLock()) {
Set<RubyClass> subclasses = this.subclasses;
if (subclasses == null) this.subclasses = subclasses = new WeakHashSet<>(4);
subclasses.add(subclass);
public void addSubclass(RubyClass subclass) {
Set<RubyClass> subclasses = this.subclasses;
if (subclasses == null) {
// check again
synchronized (this) {
subclasses = this.subclasses;
if (subclasses == null) {
this.subclasses = subclasses = Collections.synchronizedSet(new WeakHashSet<RubyClass>(4));
}
}
}

subclasses.add(subclass);
}

/**
* Remove a subclass from the weak set of subclasses.
*
* @param subclass The subclass to remove
*/
public synchronized void removeSubclass(RubyClass subclass) {
synchronized (runtime.getHierarchyLock()) {
Set<RubyClass> subclasses = this.subclasses;
if (subclasses == null) return;
public void removeSubclass(RubyClass subclass) {
Set<RubyClass> subclasses = this.subclasses;
if (subclasses == null) return;

subclasses.remove(subclass);
}
subclasses.remove(subclass);
}

/**
Expand All @@ -1149,25 +1162,21 @@ public synchronized void removeSubclass(RubyClass subclass) {
* @param subclass The subclass to remove
* @param newSubclass The subclass to replace it with
*/
public synchronized void replaceSubclass(RubyClass subclass, RubyClass newSubclass) {
synchronized (runtime.getHierarchyLock()) {
Set<RubyClass> subclasses = this.subclasses;
if (subclasses == null) return;
public void replaceSubclass(RubyClass subclass, RubyClass newSubclass) {
Set<RubyClass> subclasses = this.subclasses;
if (subclasses == null) return;

subclasses.remove(subclass);
subclasses.add(newSubclass);
}
subclasses.remove(subclass);
subclasses.add(newSubclass);
}

@Override
public void becomeSynchronized() {
// make this class and all subclasses sync
synchronized (runtime.getHierarchyLock()) {
super.becomeSynchronized();
Set<RubyClass> subclasses = this.subclasses;
if (subclasses != null) {
for (RubyClass subclass : subclasses) subclass.becomeSynchronized();
}
super.becomeSynchronized();
Set<RubyClass> subclasses = this.subclasses;
if (subclasses != null) {
for (RubyClass subclass : subclasses) subclass.becomeSynchronized();
}
}

Expand All @@ -1187,11 +1196,9 @@ public void becomeSynchronized() {
public void invalidateCacheDescendants() {
super.invalidateCacheDescendants();

synchronized (runtime.getHierarchyLock()) {
Set<RubyClass> subclasses = this.subclasses;
if (subclasses != null) {
for (RubyClass subclass : subclasses) subclass.invalidateCacheDescendants();
}
Set<RubyClass> subclasses = this.subclasses;
if (subclasses != null) {
for (RubyClass subclass : subclasses) subclass.invalidateCacheDescendants();
}
}

Expand All @@ -1207,12 +1214,7 @@ public void addInvalidatorsAndFlush(List<Invalidator> invalidators) {
if (subclasses == null || subclasses.isEmpty()) return;

// cascade into subclasses
synchronized (runtime.getHierarchyLock()) {
subclasses = this.subclasses;
if (subclasses != null) {
for (RubyClass subclass : subclasses) subclass.addInvalidatorsAndFlush(invalidators);
}
}
for (RubyClass subclass : subclasses) subclass.addInvalidatorsAndFlush(invalidators);
}

public final Ruby getClassRuntime() {
Expand Down Expand Up @@ -2325,7 +2327,7 @@ public IRubyObject invoke(ThreadContext context, IRubyObject self, String name,
protected final Ruby runtime;
private ObjectAllocator allocator; // the default allocator
protected ObjectMarshal marshal;
private Set<RubyClass> subclasses;
private volatile Set<RubyClass> subclasses;
public static final int CS_IDX_INITIALIZE = 0;
public enum CS_NAMES {
INITIALIZE("initialize");
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/org/jruby/RubyEncoding.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import org.jruby.runtime.encoding.EncodingService;
import org.jruby.runtime.opto.OptoFactory;
import org.jruby.util.ByteList;
import org.jruby.util.CodeRangeable;
import org.jruby.util.StringSupport;
import org.jruby.util.io.EncodingUtils;
import org.jruby.util.unsafe.UnsafeHolder;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyEnumerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public static IRubyObject enumeratorize(Ruby runtime, IRubyObject object, String
return new RubyEnumerator(runtime, runtime.getEnumerator(), object, runtime.fastNewSymbol(method), new IRubyObject[] {arg});
}

public static IRubyObject enumeratorize(Ruby runtime, IRubyObject object, String method, IRubyObject[] args) {
public static IRubyObject enumeratorize(Ruby runtime, IRubyObject object, String method, IRubyObject... args) {
return new RubyEnumerator(runtime, runtime.getEnumerator(), object, runtime.fastNewSymbol(method), args); // TODO: make sure it's really safe to not to copy it
}

Expand Down

0 comments on commit 131ba02

Please sign in to comment.