Skip to content

Commit 0e3d4c5

Browse files
committed
Only load neighbors when required
1 parent d122692 commit 0e3d4c5

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

core/src/main/java/io/tunabytes/bytecode/MixinsConfig.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.tunabytes.bytecode;
22

3+
import io.tunabytes.classloader.TunaClassDefiner;
4+
35
import java.io.IOException;
46
import java.io.InputStream;
57
import java.util.*;
@@ -20,15 +22,17 @@ public MixinsConfig() {
2022
properties.forEach((key, value) -> mixinEntries.add(new MixinEntry((String) key, (String) value)));
2123
InputStream neighborsStream = getClass().getResourceAsStream("/mixins-neighbors.properties");
2224
requireNonNull(neighborsStream, "mixins-neighbors.properties not found. Did you add tuna-bytes as an annotation processor?");
23-
Properties neighborsProps = new Properties();
24-
neighborsProps.load(neighborsStream);
25-
neighborsProps.forEach((key, value) -> {
26-
try {
27-
neighbors.put((String) key, Class.forName(String.valueOf(value)));
28-
} catch (ClassNotFoundException e) {
29-
e.printStackTrace();
30-
}
31-
});
25+
if (TunaClassDefiner.requiresNeighbor()) {
26+
Properties neighborsProps = new Properties();
27+
neighborsProps.load(neighborsStream);
28+
neighborsProps.forEach((key, value) -> {
29+
try {
30+
neighbors.put((String) key, Class.forName(String.valueOf(value)));
31+
} catch (ClassNotFoundException e) {
32+
e.printStackTrace();
33+
}
34+
});
35+
}
3236
} catch (IOException e) {
3337
e.printStackTrace();
3438
}

core/src/main/java/io/tunabytes/classloader/ClassDefiner.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@ Class<?> defineClass(String name,
1515
Class<?> neighbor,
1616
ClassLoader loader,
1717
ProtectionDomain protectionDomain) throws ClassFormatError;
18+
19+
default boolean requiresNeighbor() {
20+
return false;
21+
}
22+
1823
}

core/src/main/java/io/tunabytes/classloader/TunaClassDefiner.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,8 @@ public static Class<?> defineClass(String name,
7171
ProtectionDomain protectionDomain) throws ClassFormatError {
7272
return classDefiner.defineClass(name, b, 0, b.length, neighbor, loader, protectionDomain);
7373
}
74+
75+
public static boolean requiresNeighbor() {
76+
return classDefiner.requiresNeighbor();
77+
}
7478
}

java11/src/main/java/io/tunabytes/classloader/Java11.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,8 @@ public static Class<?> toClass(Class<?> neighbor, byte[] bcode) {
7171
+ " has no permission to define the class");
7272
}
7373
}
74+
75+
@Override public boolean requiresNeighbor() {
76+
return true;
77+
}
7478
}

0 commit comments

Comments
 (0)