Skip to content

Commit

Permalink
Merge pull request #1 from FlintMC/feature/java9-performance-optimiza…
Browse files Browse the repository at this point in the history
…tion

Add Java9+ support and fixes seme performance issues.
  • Loading branch information
Janrupf authored May 18, 2021
2 parents 229f53b + 0a78610 commit 414101b
Showing 1 changed file with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
*/
public class RootClassLoader extends URLClassLoader implements CommonClassLoader {

private static final Logger LOGGER = LogManager.getLogger(RootClassLoader.class);

static {
ClassLoader.registerAsParallelCapable();
}
Expand All @@ -71,7 +73,7 @@ public class RootClassLoader extends URLClassLoader implements CommonClassLoader
* @param urls The new class path of this class loader
*/
public RootClassLoader(URL[] urls) {
super(urls, null);
super(urls, getPlatformClassloader());
this.currentlyLoading = new HashSet<>();
this.plugins = new HashSet<>();
this.children = new ArrayList<>();
Expand All @@ -91,6 +93,26 @@ public RootClassLoader(URL[] urls) {
excludeFromModification("net.flintmc.launcher.");
}

/**
* Retrieves the classloader from the platform.
*
* @return The platform classloader.
*/
private static ClassLoader getPlatformClassloader() {
String javaVersionProperty = System.getProperty("java.version");

if (!javaVersionProperty.startsWith("1.")) {
try {
return (ClassLoader) ClassLoader.class
.getDeclaredMethod("getPlatformClassLoader")
.invoke(null);
} catch (Throwable ignored) {
LOGGER.warn("No platform classloader found: {}", javaVersionProperty);
}
}
return null;
}

public void addModifiedClass(String name, byte[] byteCode) {
this.modifiedClasses.put(name, byteCode);
}
Expand Down Expand Up @@ -142,7 +164,7 @@ public void excludeFromModification(String... names) {
*/
@Override
public Class<?> findClass(String name) throws ClassNotFoundException {
return findClass(name, null);
return findClass(name, (ChildClassLoader) null);
}

/**
Expand Down Expand Up @@ -274,7 +296,16 @@ public Class<?> findClass(String name, ChildClassLoader preferredLoader)
*/
@Override
public URL findResource(String name) {
return findResource(name, true);
return super.findResource(name);
// TODO: 5/18/2021
// The findResource(String, boolean) method slows down the startup
// by 10-20 seconds on the Windows operating system.
//
// I think we still need a better solution for this,
// but since there are currently no launcher plugins that could redirect the resource,
// the implementation is fine.
//
// return findResource(name, true);
}

/**
Expand Down

0 comments on commit 414101b

Please sign in to comment.