Skip to content

Commit

Permalink
Merge branch 'develop-JRL-1938'
Browse files Browse the repository at this point in the history
  • Loading branch information
teodord committed Sep 17, 2024
2 parents d9fe298 + 2032edb commit 7fd7dd8
Showing 1 changed file with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@
import java.io.InputStream;
import java.io.ObjectStreamClass;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;

import net.sf.jasperreports.engine.fill.JRAbstractLRUVirtualizer;
import net.sf.jasperreports.engine.fill.JRVirtualizationContext;
Expand Down Expand Up @@ -62,11 +61,13 @@ protected static boolean isAncestorClassLoader(ClassLoader loader)
return false;
}

protected final Map<ClassLoader,Integer> classLoadersIndexes = new HashMap<>();
protected final List<ClassLoader> classLoadersList = new ArrayList<>();
protected final AtomicInteger classLoaderIndex = new AtomicInteger();
protected final ConcurrentMap<ClassLoader,Integer> classLoadersIndexes = new ConcurrentHashMap<>();
protected final ConcurrentMap<Integer, ClassLoader> classLoaders = new ConcurrentHashMap<>();

protected final Map<Class<?>, Integer> classIndexes = new HashMap<>();
protected final List<Class<?>> classes = new ArrayList<>();
protected final AtomicInteger classIndex = new AtomicInteger();
protected final ConcurrentMap<Class<?>, Integer> classIndexes = new ConcurrentHashMap<>();
protected final ConcurrentMap<Integer, Class<?>> classes = new ConcurrentHashMap<>();

public LocalVirtualizationSerializer()
{
Expand All @@ -87,9 +88,16 @@ public int getClassloaderIdx(Class<?> clazz)
Integer idx = classLoadersIndexes.get(classLoader);
if (idx == null)
{
idx = classLoadersList.size();
classLoadersIndexes.put(classLoader, idx);
classLoadersList.add(classLoader);
idx = classLoaderIndex.getAndIncrement();
Integer previousIndex = classLoadersIndexes.putIfAbsent(classLoader, idx);
if (previousIndex == null)
{
classLoaders.put(idx, classLoader);
}
else
{
idx = previousIndex;
}
}
loaderIdx = idx;
}
Expand All @@ -103,7 +111,7 @@ public Class<?> resolveClass(ObjectStreamClass desc, int loaderIdx) throws Class
return null;
}

ClassLoader loader = classLoadersList.get(loaderIdx);
ClassLoader loader = classLoaders.get(loaderIdx);
Class<?> clazz = Class.forName(desc.getName(), false, loader);
return clazz;
}
Expand All @@ -113,9 +121,16 @@ public int getClassDescriptorIdx(Class<?> clazz)
Integer classIdx = classIndexes.get(clazz);
if (classIdx == null)
{
classIdx = classIndexes.size();
classIndexes.put(clazz, classIdx);
classes.add(clazz);
classIdx = classIndex.getAndIncrement();
Integer previousIndex = classIndexes.putIfAbsent(clazz, classIdx);
if (previousIndex == null)
{
classes.put(classIdx, clazz);
}
else
{
classIdx = previousIndex;
}
}
return classIdx;
}
Expand Down

0 comments on commit 7fd7dd8

Please sign in to comment.