Skip to content

Commit

Permalink
Only cache SRG bytes during the load of that particular class to redu…
Browse files Browse the repository at this point in the history
…ce dedotated wam usage
  • Loading branch information
LunNova committed Jan 20, 2017
1 parent 109e619 commit 317d314
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/main/java/me/nallar/modpatcher/LaunchClassLoaderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,9 @@ static void removeRedundantExclusions(Set<String> transformerExceptions) {
}
}
}

public static void releaseSrgBytes(String transformedName) {
cachedSrgClasses.remove(transformedName);
ModPatcherTransformer.pool.dropCache(transformedName);
}
}
22 changes: 13 additions & 9 deletions src/main/java/me/nallar/modpatcher/ModPatcherTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,21 @@ private static void recursivelyAddXmlFiles(File directory, Patcher patcher) {
static byte[] transformationHook(String name, byte[] originalBytes) {
LaunchClassLoaderUtil.cacheSrgBytes(name, originalBytes);

if (mixinApplicator != null) {
final byte[] finalOriginalBytes = originalBytes;
originalBytes = getMixinApplicator().getMixinTransformer().transformClass(() -> finalOriginalBytes, name).get();
}

try {
return patcher.patch(name, originalBytes);
} catch (Throwable t) {
PatcherLog.error("Failed to patch " + name, t);
if (mixinApplicator != null) {
final byte[] finalOriginalBytes = originalBytes;
originalBytes = getMixinApplicator().getMixinTransformer().transformClass(() -> finalOriginalBytes, name).get();
}

try {
return patcher.patch(name, originalBytes);
} catch (Throwable t) {
PatcherLog.error("Failed to patch " + name, t);
}
return originalBytes;
} finally {
LaunchClassLoaderUtil.releaseSrgBytes(name);
}
return originalBytes;
}

static IClassTransformer getInstance() {
Expand Down

0 comments on commit 317d314

Please sign in to comment.