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

Commits on Sep 10, 2015

  1. when a container gets terminated then a new container need a new JRub…

    …yClassloader
    
    when closing the JRubyClassLoader on a runtime the reference needs to set to null. this
    allows to reuse the global runtime which gets a new JRubyClassLoader when used again.
    use case is new ScriptionContainer().terminate() then a new instance of ScriptingContainer
    has to load jruby extensions as the first instance. note the use of the global runtime here.
    
    fixes #3300
    mkristian committed Sep 10, 2015
    Copy the full SHA
    70527c2 View commit details
  2. do search for serviceExtensions at the very end of the librarySearch

    this reduces the search especially when loading jars. there is no more
    ServiceExtension search anymore for jar-resources beside the one after
    adding the jar to the classloader.
    mkristian committed Sep 10, 2015
    Copy the full SHA
    9ceb2fe View commit details
5 changes: 4 additions & 1 deletion core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -3348,7 +3348,10 @@ public void tearDown(boolean systemExit) {
* release the runtime loader but not otherwise - you should do that manually.
*/
public void releaseClassLoader() {
if ( jrubyClassLoader != null ) getJRubyClassLoader().close();
if ( jrubyClassLoader != null ) {
getJRubyClassLoader().close();
jrubyClassLoader = null;
}
}

/**
13 changes: 2 additions & 11 deletions core/src/main/java/org/jruby/runtime/load/LibrarySearcher.java
Original file line number Diff line number Diff line change
@@ -61,25 +61,16 @@ public FoundLibrary findBySearchState(LoadService.SearchState state) {
}

public FoundLibrary findLibrary(String baseName, SuffixType suffixType) {
boolean searchedForServiceLibrary = false;

for (String suffix : suffixType.getSuffixes()) {
FoundLibrary library = findBuiltinLibrary(baseName, suffix);
if (library == null) library = findResourceLibrary(baseName, suffix);

// Since searching for a service library doesn't take the suffix into account, there's no need
// to perform it more than once.
if (library == null && !searchedForServiceLibrary) {
library = findServiceLibrary(baseName, suffix);
searchedForServiceLibrary = true;
}

if (library != null) {
return library;
}
}

return null;
return findServiceLibrary(baseName);
}

private FoundLibrary findBuiltinLibrary(String name, String suffix) {
@@ -95,7 +86,7 @@ private FoundLibrary findBuiltinLibrary(String name, String suffix) {
return null;
}

private FoundLibrary findServiceLibrary(String name, String ignored) {
private FoundLibrary findServiceLibrary(String name) {
DebugLog.JarExtension.logTry(name);
Library extensionLibrary = ClassExtensionLibrary.tryFind(runtime, name);
if (extensionLibrary != null) {
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<project>
<groupId>org.jruby.tests</groupId>
<artifactId>terminate-container-and-extensions</artifactId>
<version>1</version>
<modelVersion>4.0.0</modelVersion>

<dependencies>
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby</artifactId>
<version>@project.version@</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>rubygems</groupId>
<artifactId>thread_safe</artifactId>
<version>0.3.5</version>
<type>gem</type>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>

<repositories>
<repository>
<url>https://otto.takari.io/content/repositories/rubygems/maven/releases</url>
<id>rubygems-releases</id>
</repository>
</repositories>

<properties>
<jruby.plugins.version>1.0.10</jruby.plugins.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>de.saumya.mojo</groupId>
<artifactId>gem-maven-plugin</artifactId>
<version>${jruby.plugins.version}</version>
<executions>
<execution>
<goals><goal>initialize</goal></goals>
</execution>
</executions>
<configuration>
<jrubyVersion>1.7.22</jrubyVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.jruby.its;

import junit.framework.TestCase;

import org.jruby.embed.EmbedEvalUnit;
import org.jruby.embed.ScriptingContainer;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

public class TerminateContainerAndExtensionsTestCase {

@Test
public void terminteAndStartAgain(){
ScriptingContainer container = new ScriptingContainer();
String result = container.parse( "require 'thread_safe';ThreadSafe::Cache.superclass").run().toString();
assertEquals(result, "ThreadSafe::JRubyCacheBackend");
container.terminate();

// no things should work as before
container = new ScriptingContainer();
result = container.parse( "require 'thread_safe';ThreadSafe::Cache.superclass").run().toString();
assertEquals(result, "ThreadSafe::JRubyCacheBackend");
container.terminate();
}
}