Skip to content

Commit

Permalink
[JVM] Fix caching of defined classes by the ByteClassLoader
Browse files Browse the repository at this point in the history
- Actually use any cached class, read or defined...
- We need to use getName when name is null in either case, not
  getCanonicalName, so we avoid name clashing with static classes.
  • Loading branch information
Kaiepi committed Aug 9, 2022
1 parent 3abee01 commit 6b009db
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/vm/jvm/runtime/org/raku/nqp/runtime/ByteClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,24 @@ public Class<?> getMade(String name) {
}

public Class<?> setMade(String name, Class<?> klass) {
if (name != null)
made.put(name, new SoftReference(klass));
if (name == null)
name = klass.getName();
made.put(name, new SoftReference(klass));
return klass;
}

public Class<?> getRead(ClassLoader child, String name) {
if (name != null && made.containsKey(name))
return made.get(name).get();
if (child != null && read.containsKey(child))
if (made.containsKey(name = read.get(name)))
if (made.containsKey(name = read.get(child)))
return made.get(name).get();
return null;
}

public Class<?> setRead(ClassLoader child, String name, Class<?> klass) {
if (name == null)
name = klass.getCanonicalName();
name = klass.getName();
if (child != null)
read.put(child, name);
made.put(name, new SoftReference(klass));
Expand All @@ -58,6 +59,6 @@ public Class<?> setRead(ClassLoader child, String name, Class<?> klass) {

public Class<?> defineClass(String name, byte[] bytes) throws ClassFormatError {
Class<?> made = getMade(name);
return made == null ? setMade(name, defineClass(name, bytes, 0, bytes.length)) : null;
return made == null ? setMade(name, defineClass(name, bytes, 0, bytes.length)) : made;
}
}

0 comments on commit 6b009db

Please sign in to comment.