From 6b009dbdaee8daeb8485b9adfe9d928f2cdbb559 Mon Sep 17 00:00:00 2001 From: Ben Davies Date: Tue, 9 Aug 2022 19:46:42 +0000 Subject: [PATCH] [JVM] Fix caching of defined classes by the ByteClassLoader - 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. --- .../runtime/org/raku/nqp/runtime/ByteClassLoader.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/vm/jvm/runtime/org/raku/nqp/runtime/ByteClassLoader.java b/src/vm/jvm/runtime/org/raku/nqp/runtime/ByteClassLoader.java index e83cd20dd..dc3a7e03b 100644 --- a/src/vm/jvm/runtime/org/raku/nqp/runtime/ByteClassLoader.java +++ b/src/vm/jvm/runtime/org/raku/nqp/runtime/ByteClassLoader.java @@ -33,8 +33,9 @@ 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; } @@ -42,14 +43,14 @@ 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)); @@ -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; } }