Skip to content

Commit

Permalink
move JRuby's class-loader initialization to constructor + make it final
Browse files Browse the repository at this point in the history
release no longer nulls but loader lifespan should match runtime's anyway
kares committed Jul 16, 2017
1 parent 598f8cf commit e4876d0
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -247,7 +247,18 @@ private Ruby(RubyInstanceConfig config) {

constant = OptoFactory.newConstantWrapper(Ruby.class, this);

getJRubyClassLoader(); // force JRubyClassLoader to init if possible
// force JRubyClassLoader to init if possible
if (!Ruby.isSecurityRestricted()) {
if (config.isClassloaderDelegate()){
jrubyClassLoader = new JRubyClassLoader(config.getLoader());
}
else {
jrubyClassLoader = new SelfFirstJRubyClassLoader(config.getLoader());
}
}
else {
jrubyClassLoader = null; // a NullClassLoader object would be better ...
}

this.staticScopeFactory = new StaticScopeFactory(this);
this.beanManager = BeanManagerFactory.create(this, config.isManagementEnabled());
@@ -2579,24 +2590,7 @@ public static ClassLoader getClassLoader() {
return loader;
}

/**
* TODO the property {@link #jrubyClassLoader} will only be set in constructor. in the first call of
* {@link #getJRubyClassLoader() getJRubyClassLoader}. So the field {@link #jrubyClassLoader} can be final
* set in the constructor directly and we avoid the synchronized here.
*
* @return
*/
public synchronized JRubyClassLoader getJRubyClassLoader() {
// FIXME: Get rid of laziness and handle restricted access elsewhere
if (!Ruby.isSecurityRestricted() && jrubyClassLoader == null) {
if (config.isClassloaderDelegate()){
jrubyClassLoader = new JRubyClassLoader(config.getLoader());
}
else {
jrubyClassLoader = new SelfFirstJRubyClassLoader(config.getLoader());
}
}

public JRubyClassLoader getJRubyClassLoader() {
return jrubyClassLoader;
}

@@ -3329,9 +3323,9 @@ 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();
jrubyClassLoader = null;
if (jrubyClassLoader != null) {
jrubyClassLoader.close();
//jrubyClassLoader = null;
}
}

@@ -4952,7 +4946,7 @@ private MRIRecursionGuard oldRecursionGuard() {

// Java support
private JavaSupport javaSupport;
private JRubyClassLoader jrubyClassLoader;
private final JRubyClassLoader jrubyClassLoader;

// Management/monitoring
private BeanManager beanManager;

0 comments on commit e4876d0

Please sign in to comment.