aboutsummaryrefslogtreecommitdiff
path: root/loader/src/main/java/kr
diff options
context:
space:
mode:
authorsyeyoung <cyoung06@naver.com>2022-11-18 03:16:58 +0900
committersyeyoung <cyoung06@naver.com>2022-11-18 03:16:58 +0900
commitcf705024fe4e54f8ffcab74a08c21fe9fc89e9dd (patch)
tree6ecd46dd19d3d29ef7ba37f79c0d6731d76286e8 /loader/src/main/java/kr
parent5ba0fb7ab33e71d28e62910568de0865bbfe3c8c (diff)
downloadSkyblock-Dungeons-Guide-cf705024fe4e54f8ffcab74a08c21fe9fc89e9dd.tar.gz
Skyblock-Dungeons-Guide-cf705024fe4e54f8ffcab74a08c21fe9fc89e9dd.tar.bz2
Skyblock-Dungeons-Guide-cf705024fe4e54f8ffcab74a08c21fe9fc89e9dd.zip
- cleanup pain
Signed-off-by: syeyoung <cyoung06@naver.com>
Diffstat (limited to 'loader/src/main/java/kr')
-rwxr-xr-xloader/src/main/java/kr/syeyoung/dungeonsguide/launcher/Main.java12
-rw-r--r--loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/events/OwnerAwareASMEventHandler.java11
-rw-r--r--loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/exceptions/DungeonsGuideUnloadingException.java (renamed from loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/exceptions/ReferenceLeakedException.java)4
-rw-r--r--loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/IDGLoader.java6
-rw-r--r--loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/JarLoader.java18
-rw-r--r--loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/LocalLoader.java16
-rw-r--r--loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/RemoteLoader.java15
7 files changed, 38 insertions, 44 deletions
diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/Main.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/Main.java
index 1678c58f..2ada9dc8 100755
--- a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/Main.java
+++ b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/Main.java
@@ -23,7 +23,7 @@ import kr.syeyoung.dungeonsguide.launcher.branch.UpdateRetrieverUtil;
import kr.syeyoung.dungeonsguide.launcher.exceptions.DungeonsGuideLoadingException;
import kr.syeyoung.dungeonsguide.launcher.exceptions.NoSuitableLoaderFoundException;
import kr.syeyoung.dungeonsguide.launcher.exceptions.NoVersionFoundException;
-import kr.syeyoung.dungeonsguide.launcher.exceptions.ReferenceLeakedException;
+import kr.syeyoung.dungeonsguide.launcher.exceptions.DungeonsGuideUnloadingException;
import kr.syeyoung.dungeonsguide.launcher.gui.screen.GuiDisplayer;
import kr.syeyoung.dungeonsguide.launcher.gui.screen.GuiLoadingError;
import kr.syeyoung.dungeonsguide.launcher.gui.screen.GuiUnloadingError;
@@ -134,7 +134,7 @@ public class Main
}
}
- public void unload() throws ReferenceLeakedException {
+ public void unload() throws DungeonsGuideUnloadingException {
if (currentLoader != null && !currentLoader.isUnloadable()) {
throw new UnsupportedOperationException("Current version is not unloadable");
}
@@ -171,7 +171,7 @@ public class Main
GuiDisplayer.INSTANCE.displayGui(new GuiUnloadingError(e2));
}
GuiDisplayer.INSTANCE.displayGui(new GuiLoadingError(e));
- } catch (ReferenceLeakedException e) {
+ } catch (DungeonsGuideUnloadingException e) {
GuiDisplayer.INSTANCE.displayGui(new GuiUnloadingError(e));
}
})
@@ -221,17 +221,17 @@ public class Main
GuiDisplayer.INSTANCE.displayGui(new GuiUnloadingError(e2));
}
GuiDisplayer.INSTANCE.displayGui(new GuiLoadingError(e));
- } catch (ReferenceLeakedException e) {
+ } catch (DungeonsGuideUnloadingException e) {
GuiDisplayer.INSTANCE.displayGui(new GuiUnloadingError(e));
}
}
}
- public void reload(IDGLoader newLoader) throws DungeonsGuideLoadingException, ReferenceLeakedException {
+ public void reload(IDGLoader newLoader) throws DungeonsGuideLoadingException, DungeonsGuideUnloadingException {
try {
unload();
load(newLoader);
- } catch (DungeonsGuideLoadingException | ReferenceLeakedException | UnsupportedOperationException e) {
+ } catch (DungeonsGuideLoadingException | DungeonsGuideUnloadingException | UnsupportedOperationException e) {
dgInterface = null;
currentLoader = null;
diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/events/OwnerAwareASMEventHandler.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/events/OwnerAwareASMEventHandler.java
index 3475e672..83f78720 100644
--- a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/events/OwnerAwareASMEventHandler.java
+++ b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/events/OwnerAwareASMEventHandler.java
@@ -4,6 +4,7 @@ import static org.objectweb.asm.Opcodes.*;
import java.lang.reflect.Method;
import java.util.HashMap;
+import java.util.WeakHashMap;
import net.minecraftforge.fml.common.ModContainer;
@@ -24,7 +25,6 @@ public class OwnerAwareASMEventHandler implements IEventListener
private static int IDs = 0;
private static final String HANDLER_DESC = Type.getInternalName(IEventListener.class);
private static final String HANDLER_FUNC_DESC = Type.getMethodDescriptor(IEventListener.class.getDeclaredMethods()[0]);
- private static final HashMap<Method, Class<?>> cache = Maps.newHashMap();
private static final boolean GETCONTEXT = Boolean.parseBoolean(System.getProperty("fml.LogContext", "false"));
private final IEventListener handler;
@@ -63,11 +63,6 @@ public class OwnerAwareASMEventHandler implements IEventListener
public Class<?> createWrapper(Method callback)
{
- if (cache.containsKey(callback))
- {
- return cache.get(callback);
- }
-
ClassWriter cw = new ClassWriter(0);
MethodVisitor mv;
@@ -116,9 +111,7 @@ public class OwnerAwareASMEventHandler implements IEventListener
mv.visitEnd();
}
cw.visitEnd();
- Class<?> ret = new ASMClassLoader(callback.getDeclaringClass().getClassLoader()).define(name, cw.toByteArray());
- cache.put(callback, ret);
- return ret;
+ return new ASMClassLoader(callback.getDeclaringClass().getClassLoader()).define(name, cw.toByteArray());
}
private String getUniqueName(Method callback)
diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/exceptions/ReferenceLeakedException.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/exceptions/DungeonsGuideUnloadingException.java
index 3a88b862..6b2850f6 100644
--- a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/exceptions/ReferenceLeakedException.java
+++ b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/exceptions/DungeonsGuideUnloadingException.java
@@ -18,5 +18,7 @@
package kr.syeyoung.dungeonsguide.launcher.exceptions;
-public class ReferenceLeakedException extends Exception {
+public class DungeonsGuideUnloadingException extends Exception {
+ public DungeonsGuideUnloadingException(String message) {super(message);}
+ public DungeonsGuideUnloadingException(Exception cause) {super(cause);}
}
diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/IDGLoader.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/IDGLoader.java
index 1edc0b7c..52982355 100644
--- a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/IDGLoader.java
+++ b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/IDGLoader.java
@@ -20,14 +20,12 @@ package kr.syeyoung.dungeonsguide.launcher.loader;
import kr.syeyoung.dungeonsguide.launcher.DGInterface;
import kr.syeyoung.dungeonsguide.launcher.exceptions.DungeonsGuideLoadingException;
-import kr.syeyoung.dungeonsguide.launcher.exceptions.ReferenceLeakedException;
-
-import java.io.IOException;
+import kr.syeyoung.dungeonsguide.launcher.exceptions.DungeonsGuideUnloadingException;
public interface IDGLoader {
DGInterface loadDungeonsGuide() throws DungeonsGuideLoadingException;
DGInterface getInstance();
- void unloadDungeonsGuide() throws ReferenceLeakedException;
+ void unloadDungeonsGuide() throws DungeonsGuideUnloadingException;
boolean isUnloadable();
diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/JarLoader.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/JarLoader.java
index 39fcbf58..61dec833 100644
--- a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/JarLoader.java
+++ b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/JarLoader.java
@@ -19,22 +19,16 @@
package kr.syeyoung.dungeonsguide.launcher.loader;
import kr.syeyoung.dungeonsguide.launcher.DGInterface;
-import kr.syeyoung.dungeonsguide.launcher.Main;
import kr.syeyoung.dungeonsguide.launcher.exceptions.DungeonsGuideLoadingException;
-import kr.syeyoung.dungeonsguide.launcher.exceptions.ReferenceLeakedException;
+import kr.syeyoung.dungeonsguide.launcher.exceptions.DungeonsGuideUnloadingException;
import org.apache.commons.io.IOUtils;
-import sun.misc.Resource;
import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.PhantomReference;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
-import java.lang.ref.WeakReference;
-import java.net.URL;
-import java.net.URLClassLoader;
import java.util.HashMap;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -94,13 +88,17 @@ public class JarLoader implements IDGLoader {
}
@Override
- public void unloadDungeonsGuide() throws ReferenceLeakedException {
+ public void unloadDungeonsGuide() throws DungeonsGuideUnloadingException {
classLoader = null;
- dgInterface.unload();
+ try {
+ dgInterface.unload();
+ } catch (Exception e) {
+ throw new DungeonsGuideUnloadingException(e);
+ }
dgInterface = null;
System.gc();// pls do
Reference<? extends ClassLoader> t = refQueue.poll();
- if (t == null) throw new ReferenceLeakedException(); // Why do you have to be that strict? Well, to tell them to actually listen on DungeonsGuideReloadListener. If it starts causing issues then I will remove check cus it's not really loaded (classes are loaded by child classloader)
+ if (t == null) throw new DungeonsGuideUnloadingException("Reference Leaked"); // Why do you have to be that strict? Well, to tell them to actually listen on DungeonsGuideReloadListener. If it starts causing issues then I will remove check cus it's not really loaded (classes are loaded by child classloader)
t.clear();
phantomReference = null;
}
diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/LocalLoader.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/LocalLoader.java
index ec3e59fb..519578f1 100644
--- a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/LocalLoader.java
+++ b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/LocalLoader.java
@@ -20,19 +20,15 @@ package kr.syeyoung.dungeonsguide.launcher.loader;
import kr.syeyoung.dungeonsguide.launcher.DGInterface;
import kr.syeyoung.dungeonsguide.launcher.exceptions.DungeonsGuideLoadingException;
-import kr.syeyoung.dungeonsguide.launcher.exceptions.ReferenceLeakedException;
+import kr.syeyoung.dungeonsguide.launcher.exceptions.DungeonsGuideUnloadingException;
import org.apache.commons.io.IOUtils;
import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.PhantomReference;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
-import java.util.HashMap;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
public class LocalLoader implements IDGLoader {
private DGInterface dgInterface;
@@ -84,13 +80,17 @@ public class LocalLoader implements IDGLoader {
}
@Override
- public void unloadDungeonsGuide() throws ReferenceLeakedException {
+ public void unloadDungeonsGuide() throws DungeonsGuideUnloadingException {
classLoader = null;
- dgInterface.unload();
+ try {
+ dgInterface.unload();
+ } catch (Exception e) {
+ throw new DungeonsGuideUnloadingException(e);
+ }
dgInterface = null;
System.gc();// pls do
Reference<? extends ClassLoader> t = refQueue.poll();
- if (t == null) throw new ReferenceLeakedException(); // Why do you have to be that strict? Well, to tell them to actually listen on DungeonsGuideReloadListener. If it starts causing issues then I will remove check cus it's not really loaded (classes are loaded by child classloader)
+ if (t == null) throw new DungeonsGuideUnloadingException("Reference Leaked"); // Why do you have to be that strict? Well, to tell them to actually listen on DungeonsGuideReloadListener. If it starts causing issues then I will remove check cus it's not really loaded (classes are loaded by child classloader)
t.clear();
phantomReference = null;
}
diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/RemoteLoader.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/RemoteLoader.java
index ceafb6f7..e4becc53 100644
--- a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/RemoteLoader.java
+++ b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/RemoteLoader.java
@@ -20,12 +20,11 @@ package kr.syeyoung.dungeonsguide.launcher.loader;
import kr.syeyoung.dungeonsguide.launcher.DGInterface;
import kr.syeyoung.dungeonsguide.launcher.branch.Update;
-import kr.syeyoung.dungeonsguide.launcher.branch.UpdateBranch;
import kr.syeyoung.dungeonsguide.launcher.branch.UpdateRetrieverUtil;
import kr.syeyoung.dungeonsguide.launcher.exceptions.DungeonsGuideLoadingException;
import kr.syeyoung.dungeonsguide.launcher.exceptions.InvalidSignatureException;
import kr.syeyoung.dungeonsguide.launcher.exceptions.NoVersionFoundException;
-import kr.syeyoung.dungeonsguide.launcher.exceptions.ReferenceLeakedException;
+import kr.syeyoung.dungeonsguide.launcher.exceptions.DungeonsGuideUnloadingException;
import org.apache.commons.io.IOUtils;
import java.io.ByteArrayInputStream;
@@ -35,7 +34,6 @@ import java.lang.ref.PhantomReference;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.util.HashMap;
-import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -123,13 +121,18 @@ public class RemoteLoader implements IDGLoader {
}
@Override
- public void unloadDungeonsGuide() throws ReferenceLeakedException {
+ public void unloadDungeonsGuide() throws DungeonsGuideUnloadingException {
classLoader = null;
- dgInterface.unload();
+
+ try {
+ dgInterface.unload();
+ } catch (Exception e) {
+ throw new DungeonsGuideUnloadingException(e);
+ }
dgInterface = null;
System.gc();// pls do
Reference<? extends ClassLoader> t = refQueue.poll();
- if (t == null) throw new ReferenceLeakedException(); // Why do you have to be that strict? Well, to tell them to actually listen on DungeonsGuideReloadListener. If it starts causing issues then I will remove check cus it's not really loaded (classes are loaded by child classloader)
+ if (t == null) throw new DungeonsGuideUnloadingException("Reference Leaked"); // Why do you have to be that strict? Well, to tell them to actually listen on DungeonsGuideReloadListener. If it starts causing issues then I will remove check cus it's not really loaded (classes are loaded by child classloader)
t.clear();
phantomReference = null;
}