Skip to content

Commit

Permalink
Merge branch 'jruby-1_7'
Browse files Browse the repository at this point in the history
* jruby-1_7:
  close JRuby's class-loader resources on Java 7+ (but only in embed uses)
  make fields final
  revert "close (URLClassLoader's) resources on JRubyClassLoader#tearDown"

Conflicts:
	core/src/main/java/org/jruby/Ruby.java
	core/src/main/java/org/jruby/embed/ScriptingContainer.java
	core/src/main/java/org/jruby/util/JRubyClassLoader.java
kares committed Jul 29, 2015
2 parents 9adaca4 + 1c19d0c commit e840a7d
Showing 4 changed files with 35 additions and 7 deletions.
16 changes: 11 additions & 5 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -3307,7 +3307,7 @@ public void tearDown(boolean systemExit) {

getSelectorPool().cleanup();

releaseClassLoader();
// NOTE: its intentional that we're not doing releaseClassLoader();

if (config.isProfilingEntireRun()) {
// not using logging because it's formatted
@@ -3332,10 +3332,16 @@ public void tearDown(boolean systemExit) {
}
}

private void releaseClassLoader() {
if (getJRubyClassLoader() != null) {
getJRubyClassLoader().close();
}
/**
* By default {@link #tearDown(boolean)} does not release the class-loader's
* resources as threads might be still running accessing the classes/packages
* even after the runtime has been torn down.
*
* This method exists to handle such cases, e.g. with embedded uses we always
* release the runtime loader but not otherwise - you should do that manually.
*/
public void releaseClassLoader() {
JRubyClassLoader.close( getJRubyClassLoader() );
}

/**
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/embed/ScriptingContainer.java
Original file line number Diff line number Diff line change
@@ -1854,6 +1854,8 @@ public void terminate() {
LocalContextProvider provider = getProvider();
if (provider.isRuntimeInitialized()) {
provider.getRuntime().tearDown(false);
// NOTE: Ruby#tearDown does getJRubyClassLoader().tearDown()
provider.getRuntime().releaseClassLoader();
}
provider.terminate();
}
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/javasupport/JavaEmbedUtils.java
Original file line number Diff line number Diff line change
@@ -190,8 +190,8 @@ public static interface EvalUnit {
* compiler).
*/
public static class InterpretedEvalUnit implements EvalUnit {
private Ruby runtime;
private Node node;
private final Ruby runtime;
private final Node node;

protected InterpretedEvalUnit(Ruby runtime, Node node) {
this.runtime = runtime;
20 changes: 20 additions & 0 deletions core/src/main/java/org/jruby/util/JRubyClassLoader.java
Original file line number Diff line number Diff line change
@@ -128,6 +128,26 @@ public void close() {
catch (Exception ex) { LOG.debug(ex); }
}

/**
* Helper to close the JRuby class-loader.
* @param loader
* @note This is internal API, do not rely on it to exists!
*/
public static void close(final JRubyClassLoader loader) {
if ( loader == null ) return;
// URLClassLoader#close only available since Java 7 :
try {
URLClassLoader.class.getMethod("close").invoke(loader);
}
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) {

0 comments on commit e840a7d

Please sign in to comment.