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: a7b4227e432e
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6493b3a93dcc
Choose a head ref
  • 4 commits
  • 4 files changed
  • 2 contributors

Commits on Oct 31, 2017

  1. Copy the full SHA
    78e5add View commit details
  2. Cache jar paths instead of URLs

    Since these are always paths to files, cache the paths instead of URLs
    Also rename tempUrls to cachedJarPaths
    jpinsonault authored and headius committed Oct 31, 2017
    Copy the full SHA
    882932f View commit details
  3. Copy the full SHA
    b7cb5fc View commit details
  4. Copy the full SHA
    6493b3a View commit details
Original file line number Diff line number Diff line change
@@ -29,10 +29,11 @@
*/
package org.jruby.embed.internal;

import java.util.Map;
import org.jruby.Ruby;
import org.jruby.embed.LocalVariableBehavior;

import java.util.Map;

/**
*
* @author Yoko Harada <yokolet@gmail.com>
24 changes: 24 additions & 0 deletions core/src/main/java/org/jruby/util/JRubyClassLoader.java
Original file line number Diff line number Diff line change
@@ -37,6 +37,9 @@
import java.io.OutputStream;
import java.lang.management.ManagementFactory;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.jruby.util.log.Logger;
import org.jruby.util.log.LoggerFactory;
@@ -62,6 +65,8 @@ public class JRubyClassLoader extends ClassDefiningJRubyClassLoader {

private static volatile File tempDir;

private List<String> cachedJarPaths = Collections.synchronizedList(new ArrayList<String>());

public JRubyClassLoader(ClassLoader parent) {
super(parent);
}
@@ -86,6 +91,8 @@ public void addURL(URL url) {
out.close();
in.close();
url = f.toURI().toURL();

cachedJarPaths.add(URLUtil.getPath(url));
}
catch (IOException e) {
throw new RuntimeException("BUG: we can not copy embedded jar to temp directory", e);
@@ -183,6 +190,23 @@ public void close() {
getJDBCDriverUnloader().run();
}
catch (Exception ex) { LOG.debug(ex); }

terminateJarIndexCacheEntries();
}

protected void terminateJarIndexCacheEntries() {
for (String jarPath : cachedJarPaths){
try {
// Remove reference from jar cache
JarResource.removeJarResource(jarPath);

// Delete temp jar on disk
File jarFile = new File(jarPath);
jarFile.delete();
} catch (Exception e) {
// keep trying to clean up other temp jars
}
}
}

@Deprecated
16 changes: 16 additions & 0 deletions core/src/main/java/org/jruby/util/JarCache.java
Original file line number Diff line number Diff line change
@@ -153,4 +153,20 @@ public JarIndex getIndex(String jarPath) {
return index;
}
}

public boolean remove(String jarPath){
String cacheKey = jarPath;

synchronized (indexCache) {
JarIndex index = indexCache.get(cacheKey);
if (index == null){
return false;
}
else{
index.release();
indexCache.remove(cacheKey);
return true;
}
}
}
}
6 changes: 5 additions & 1 deletion core/src/main/java/org/jruby/util/JarResource.java
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

abstract class JarResource extends AbstractFileResource {
public abstract class JarResource extends AbstractFileResource {
private static Pattern PREFIX_MATCH = Pattern.compile("^(?:jar:)?(?:file:)?(.*)$");

private static final JarCache jarCache = new JarCache();
@@ -79,6 +79,10 @@ private static JarResource createJarResource(String jarPath, String entryPath, b
return null;
}

public static boolean removeJarResource(String jarPath){
return jarCache.remove(jarPath);
}

private final String jarPrefix;
private final JarFileStat fileStat;