Skip to content

Commit

Permalink
el-api 5.0.1 now avoids memory leaks
Browse files Browse the repository at this point in the history
- so there is no need to use the reflection to clear the cache
- also it would not work any more as the field is not static now)
  • Loading branch information
dmatej committed Jul 1, 2022
1 parent 4b31687 commit 639fe4f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 82 deletions.
Expand Up @@ -1615,24 +1615,16 @@ public void preDestroy() {
/**
* Stop the class loader.
*
* @exception LifecycleException if a lifecycle error occurs
* @throws LifecycleException if a lifecycle error occurs
*/
public void stop() throws Exception {

if (!started) {
return;
}

// START GlassFish Issue 587
purgeELBeanClasses();
// END GlassFish Issue 587

/*
* Clearing references should be done before setting started to
* false, due to possible side effects.
* In addition, set this classloader as the Thread's context
* classloader, see IT 9894 for details
*/
// Clearing references should be done before setting started to
// false, due to possible side effects.
// In addition, set this classloader as the Thread's context classloader
ClassLoader curCl = null;
try {
curCl = Thread.currentThread().getContextClassLoader();
Expand All @@ -1644,9 +1636,7 @@ public void stop() throws Exception {
}
}

// START SJSAS 6258619
close();
// END SJSAS 6258619

started = false;

Expand Down Expand Up @@ -3001,80 +2991,23 @@ protected static void deleteDir(File dir) {

}

// START SJSAS 6344989
public void addByteCodePreprocessor(BytecodePreprocessor preprocessor) {
byteCodePreprocessors.add(preprocessor);
}
// END SJSAS 6344989


// START GlassFish Issue 587
/*
* Purges all bean classes that were loaded by this WebappClassLoader
* from the caches maintained by jakarta.el.BeanELResolver, in order to
* avoid this WebappClassLoader from leaking.
*/
private void purgeELBeanClasses() {

Field fieldlist[] = jakarta.el.BeanELResolver.class.getDeclaredFields();
for (Field fld : fieldlist) {
if (fld.getName().equals("properties")) {
purgeELBeanClasses(fld);
break;
}
}
}

/*
* Purges all bean classes that were loaded by this WebappClassLoader
* from the cache represented by the given reflected field.
/**
* Create and return a temporary loader with the same visibility
* as this loader. The temporary loader may be used to load
* resources or any other application classes for the purposes of
* introspecting them for annotations. The persistence provider
* should not maintain any references to the temporary loader,
* or any objects loaded by it.
*
* @param fld The reflected field from which to remove the bean classes
* that were loaded by this WebappClassLoader
* @return A temporary classloader with the same classpath as this loader
*/
private void purgeELBeanClasses(final Field fld) {

setAccessible(fld);

Map<Class, ?> m = null;
try {
m = getBeanELResolverProperties(fld);
} catch (IllegalAccessException iae) {
logger.log(Level.WARNING, LogFacade.UNABLE_PURGE_BEAN_CLASSES, iae);
return;
}

if (m.size() == 0) {
return;
}

Iterator<Class> iter = m.keySet().iterator();
while (iter.hasNext()) {
Class<?> mbeanClass = iter.next();
if (this.equals(mbeanClass.getClassLoader())) {
iter.remove();
}
}
}

@SuppressWarnings("unchecked")
private static Map<Class, ?> getBeanELResolverProperties(Field fld) throws IllegalAccessException {
return (Map<Class, ?>)fld.get(null);
}
// END GlassFish Issue 587

/**
* Create and return a temporary loader with the same visibility
* as this loader. The temporary loader may be used to load
* resources or any other application classes for the purposes of
* introspecting them for annotations. The persistence provider
* should not maintain any references to the temporary loader,
* or any objects loaded by it.
*
* @return A temporary classloader with the same classpath as this loader
*/
@Override
public ClassLoader copy() {
@Override
public ClassLoader copy() {
logger.entering("WebModuleListener$InstrumentableWebappClassLoader", "copy");
// set getParent() as the parent of the cloned class loader
return AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>() {
Expand Down
2 changes: 1 addition & 1 deletion nucleus/parent/pom.xml
Expand Up @@ -73,7 +73,7 @@
<!-- Jakarta API Versions -->

<!-- Jakarta Expression Language -->
<jakarta.el-api.version>5.0.0</jakarta.el-api.version>
<jakarta.el-api.version>5.0.1</jakarta.el-api.version>
<expressly.version>5.0.0-M2</expressly.version>

<!-- Jakarta Servlet -->
Expand Down

0 comments on commit 639fe4f

Please sign in to comment.