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

Commits on Jul 25, 2015

  1. Copy the full SHA
    48e8096 View commit details
  2. Copy the full SHA
    59c5e4b View commit details
  3. depreacate JRubyClassLoader's getJDBCDriverUnloader

    (its un-used - but still should not be part of public API)
    kares committed Jul 25, 2015
    Copy the full SHA
    b69e4f8 View commit details
  4. Copy the full SHA
    bcbef59 View commit details
  5. Copy the full SHA
    2b28036 View commit details
  6. un-used imports

    kares committed Jul 25, 2015
    Copy the full SHA
    efa6ce0 View commit details
  7. Copy the full SHA
    83c47ba View commit details
4 changes: 0 additions & 4 deletions core/src/main/java/org/jruby/RubyInstanceConfig.java
Original file line number Diff line number Diff line change
@@ -58,9 +58,7 @@
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -75,8 +73,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.regex.Pattern;

/**
9 changes: 7 additions & 2 deletions core/src/main/java/org/jruby/embed/ScriptingContainer.java
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@
*/
package org.jruby.embed;

import java.io.Closeable;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.Reader;
@@ -1896,8 +1897,11 @@ public PrintStream getErr() {
* @since JRuby 1.5.0
*/
public void terminate() {
if (getProvider().isRuntimeInitialized()) getProvider().getRuntime().tearDown(false);
getProvider().terminate();
LocalContextProvider provider = getProvider();
if (provider.isRuntimeInitialized()) {
provider.getRuntime().tearDown(false);
}
provider.terminate();
}

/**
@@ -1908,6 +1912,7 @@ public void terminate() {
*
* @since JRuby 1.6.0
*/
@Override
public void finalize() throws Throwable {
super.finalize();
terminate();
43 changes: 28 additions & 15 deletions core/src/main/java/org/jruby/util/JRubyClassLoader.java
Original file line number Diff line number Diff line change
@@ -58,12 +58,13 @@ public class JRubyClassLoader extends URLClassLoader implements ClassDefiningCla
private static final Logger LOG = LoggerFactory.getLogger("JRubyClassLoader");

private final static ProtectionDomain DEFAULT_DOMAIN;

static {
ProtectionDomain defaultDomain = null;
try {
defaultDomain = JRubyClassLoader.class.getProtectionDomain();
} catch (SecurityException se) {
}
catch (SecurityException se) {
// just use null since we can't acquire protection domain
}
DEFAULT_DOMAIN = defaultDomain;
@@ -142,13 +143,24 @@ public void tearDown(boolean debug) {
// A hack to allow unloading all JDBC Drivers loaded by this classloader.
// See http://bugs.jruby.org/4226
getJDBCDriverUnloader().run();
} catch (Exception e) {
if (debug) {
LOG.debug(e);
}
}
catch (Exception e) {
if (debug) LOG.debug(e);
}
// if we're on Java 7+ call URLClassLoader#close :
try {
URLClassLoader.class.getMethod("close").invoke(this);
}
catch (NoSuchMethodException ex) { /* noop on Java 6 */ }
catch (IllegalAccessException ex) {
LOG.info("unexpected illegal access: ", ex);
}
catch (Exception ex) {
LOG.debug(ex);
}
}

@Deprecated
public synchronized Runnable getJDBCDriverUnloader() {
if (unloader == null) {
try {
@@ -162,9 +174,9 @@ public synchronized Runnable getJDBCDriverUnloader() {

Class unloaderClass = defineClass("org.jruby.util.JDBCDriverUnloader", baos.toByteArray());
unloader = (Runnable) unloaderClass.newInstance();
} catch (Exception e) {
throw new RuntimeException(e);
}
catch (RuntimeException e) { throw e; }
catch (Exception e) { throw new RuntimeException(e); }
}
return unloader;
}
@@ -330,18 +342,19 @@ private static void close(Closeable resource) {
if (resource != null) {
try {
resource.close();
} catch (IOException ignore) {
}
catch (IOException ignore) { /* ignored */ }
}
}

private void definePackageInternal(String pkgname) {
if (getPackage(pkgname) == null) {
private void definePackageInternal(final String name) {
if (getPackage(name) == null) {
try {
definePackage(pkgname, null, null, null, null, null, null, null);
} catch (IllegalArgumentException iae) {
if (getPackage(pkgname) == null) {
throw new AssertionError("Cannot find package " + pkgname);
definePackage(name, null, null, null, null, null, null, null);
}
catch (IllegalArgumentException iae) {
if (getPackage(name) == null) {
throw new AssertionError("Cannot find package " + name);
}
}
}
105 changes: 77 additions & 28 deletions core/src/main/java/org/jruby/util/collections/WeakHashSet.java
Original file line number Diff line number Diff line change
@@ -25,28 +25,40 @@
***** END LICENSE BLOCK *****/
package org.jruby.util.collections;

import java.util.*;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import java.util.WeakHashMap;

/**
* A simple set that uses weak references to ensure that its elements can be garbage collected.
* See WeakHashMap.
*
* @see java.util.WeakHashMap
* @see java.util.HashSet
*
* @author <a href="http://www.cs.auckland.ac.nz/~robert/">Robert Egglestone</a>
*/
public class WeakHashSet<T> implements Set<T> {
private WeakHashMap<T,Object> map;
public class WeakHashSet<T> implements Set<T>, Cloneable {

// Dummy value to associate with an Object in the backing Map
private static final Object PRESENT = Boolean.TRUE;

private final WeakHashMap<T, Object> map;

public WeakHashSet() {
map = new WeakHashMap<T,Object>();
map = new WeakHashMap<T, Object>();
}

public WeakHashSet(int size) {
map = new WeakHashMap<T,Object>(size);
map = new WeakHashMap<T, Object>(size);
}

public boolean add(T o) {
Object previousValue = map.put(o, null);
return previousValue == null;
return map.put(o, PRESENT) == null;
}

public boolean remove(Object o) {
return map.remove(o) == PRESENT;
}

public Iterator<T> iterator() {
@@ -61,47 +73,84 @@ public boolean isEmpty() {
return map.isEmpty();
}

public void clear() {
map.clear();
}

public boolean contains(Object o) {
return map.containsKey(o);
}

public boolean remove(Object o) {
boolean contains = contains(o);
map.remove(o);
return contains;
public boolean containsAll(Collection<?> coll) {
return map.keySet().containsAll(coll);
}

public boolean removeAll(Collection collection) {
return map.keySet().removeAll(collection);
public boolean removeAll(Collection<?> coll) {
return map.keySet().removeAll(coll);
}

public boolean retainAll(Collection collection) {
return map.keySet().retainAll(collection);
public boolean retainAll(Collection<?> coll) {
return map.keySet().retainAll(coll);
}

public void clear() {
map.clear();
public boolean addAll(Collection<? extends T> coll) {
boolean added = false;
for (T i: coll) {
add(i);
added = true;
}
return added;
}

public Object[] toArray() {
return map.keySet().toArray();
}

public boolean containsAll(Collection arg0) {
return map.keySet().containsAll(arg0);
public <T> T[] toArray(final T[] arr) {
return map.keySet().toArray(arr);
}

public boolean addAll(Collection<? extends T> arg0) {
boolean added = false;
for (T i: arg0) {
add(i);
added = true;
@Override
public boolean equals(final Object o) {
if ( o == this ) return true;
if ( o instanceof Set ) {
final Set that = (Set) o;
if ( that.size() != this.size() ) return false;
try {
return containsAll(that);
}
catch (ClassCastException ignore) { /* return false; */ }
}
return added;
return false;
}

@Override
public int hashCode() {
return 11 * map.hashCode();
}

public <T> T[] toArray(T[] arg0) {
return map.keySet().toArray(arg0);
@Override
public WeakHashSet<T> clone() {
//WeakHashSet<T> newSet = (WeakHashSet<T>) super.clone();
//newSet.map = (WeakHashMap<T, Object>) map.clone();
WeakHashSet<T> newSet = new WeakHashSet<T>(map.size());
newSet.map.putAll(this.map);
return newSet;
}

@Override
public String toString() {
Iterator<T> it = iterator();
if ( ! it.hasNext() ) return "[]";

StringBuilder sb = new StringBuilder();
sb.append('[');
while (true) {
final T e = it.next();
sb.append(e == this ? "(this Collection)" : e);
if ( ! it.hasNext() ) return sb.append(']').toString();
sb.append(',').append(' ');
}
}

}
Original file line number Diff line number Diff line change
@@ -30,17 +30,16 @@
***** END LICENSE BLOCK *****/
package org.jruby.util.collections;

import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.Map;

/**
* A Map that holds its values weakly and uses object identity for keys.
* Map-like that holds its values weakly and uses object identity for keys.
*/
public class WeakValuedIdentityMap<Key, Value> extends WeakValuedMap<Key, Value> {
@Override
protected Map<Key, KeyedReference<Key, Value>> newMap() {
return Collections.synchronizedMap(new IdentityHashMap());
return Collections.synchronizedMap( new IdentityHashMap<Key, KeyedReference<Key, Value>>() );
}
}
38 changes: 18 additions & 20 deletions core/src/main/java/org/jruby/util/collections/WeakValuedMap.java
Original file line number Diff line number Diff line change
@@ -32,52 +32,50 @@

import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
* A Map that holds its values weakly and uses object identity for keys.
* Map-like that holds its values weakly (backed by a concurrent hash map).
*/
public class WeakValuedMap<Key, Value> {
private final ReferenceQueue deadReferences = new ReferenceQueue();
private final Map<Key, KeyedReference<Key, Value>> references = newMap();

public void put(Key key, Value value) {
private final Map<Key, KeyedReference<Key, Value>> map = newMap();
@SuppressWarnings("unchecked")
private final ReferenceQueue<Value> deadRefs = new ReferenceQueue();

public final void put(Key key, Value value) {
cleanReferences();
references.put(key, new KeyedReference(value, key, deadReferences));
map.put(key, new KeyedReference<Key, Value>(value, key, deadRefs));
}

public Value get(Key key) {
public final Value get(Key key) {
cleanReferences();
KeyedReference<Key, Value> reference = references.get(key);
if (reference == null) {
return null;
}
KeyedReference<Key, Value> reference = map.get(key);
if (reference == null) return null;
return reference.get();
}

protected Map<Key, KeyedReference<Key, Value>> newMap() {
return new ConcurrentHashMap();
return new ConcurrentHashMap<Key, KeyedReference<Key, Value>>();
}

protected static class KeyedReference<Key, Value> extends WeakReference<Value> {
private final Key key;

public KeyedReference(Value object, Key key, ReferenceQueue queue) {
protected final Key key;

public KeyedReference(Value object, Key key, ReferenceQueue<? super Value> queue) {
super(object, queue);
this.key = key;
}

public Key key() {
return key;
}
}

@SuppressWarnings("unchecked")
private void cleanReferences() {
KeyedReference ref;
while ((ref = (KeyedReference) deadReferences.poll()) != null) {
references.remove((ref.key()));
KeyedReference<Key, Value> ref;
while ( ( ref = (KeyedReference) deadRefs.poll() ) != null ) {
map.remove( ref.key );
}
}
}