mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-23 00:42:05 +01:00
Ease ClassLoader Deadlocks Where Possible
With Java 7 we can register the classloader as parallel capable to prevent deadlocks caused by certain scenarios. Due to the nature of PluginClassLoader this isn't completely safe, but we can make it safer by switching to concurrency focused collections. Either way this is far better than crashing the server. By: md_5 <git@md-5.net>
This commit is contained in:
parent
b48983bff8
commit
2f1a805931
2 changed files with 8 additions and 3 deletions
|
@ -12,6 +12,7 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
@ -48,7 +49,7 @@ import org.yaml.snakeyaml.error.YAMLException;
|
|||
public final class JavaPluginLoader implements PluginLoader {
|
||||
final Server server;
|
||||
private final Pattern[] fileFilters = new Pattern[] { Pattern.compile("\\.jar$"), };
|
||||
private final Map<String, Class<?>> classes = new HashMap<String, Class<?>>();
|
||||
private final Map<String, Class<?>> classes = new ConcurrentHashMap<String, Class<?>>();
|
||||
private final List<PluginClassLoader> loaders = new CopyOnWriteArrayList<PluginClassLoader>();
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,9 +9,9 @@ import java.net.URL;
|
|||
import java.net.URLClassLoader;
|
||||
import java.security.CodeSigner;
|
||||
import java.security.CodeSource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.Manifest;
|
||||
|
@ -25,7 +25,7 @@ import org.bukkit.plugin.PluginDescriptionFile;
|
|||
*/
|
||||
final class PluginClassLoader extends URLClassLoader {
|
||||
private final JavaPluginLoader loader;
|
||||
private final Map<String, Class<?>> classes = new HashMap<String, Class<?>>();
|
||||
private final Map<String, Class<?>> classes = new ConcurrentHashMap<String, Class<?>>();
|
||||
private final PluginDescriptionFile description;
|
||||
private final File dataFolder;
|
||||
private final File file;
|
||||
|
@ -36,6 +36,10 @@ final class PluginClassLoader extends URLClassLoader {
|
|||
private JavaPlugin pluginInit;
|
||||
private IllegalStateException pluginState;
|
||||
|
||||
static {
|
||||
ClassLoader.registerAsParallelCapable();
|
||||
}
|
||||
|
||||
PluginClassLoader(final JavaPluginLoader loader, final ClassLoader parent, final PluginDescriptionFile description, final File dataFolder, final File file) throws IOException, InvalidPluginException, MalformedURLException {
|
||||
super(new URL[] {file.toURI().toURL()}, parent);
|
||||
Validate.notNull(loader, "Loader cannot be null");
|
||||
|
|
Loading…
Add table
Reference in a new issue