2 ms·
Dynamic classes cannot be GC'd without the classloader being dereferenced. In this case, if eval used an existing classloader we would end up exhausting metaspa
by whiteros_e 2y ago
Dynamic classes cannot be GC'd without the classloader being dereferenced. In this case, if eval used an existing classloader we would end up exhausting metaspace and leading to MaxPermGen exception.
Initial Clojure implementation was checking for an already created classloader and tried to reuse. They had commented out the code that was doing it.
Link to the code in the compiler: https://github.com/clojure/clojure/blob/clojure-1.11.0/src/jvm/clojure/lang/Compiler.java#L7154 https://github.com/clojure/clojure/blob/clojure-1.11.0/src/j...
- aardvark179 2y agoThese days there is some Machinery in the JVM for creating truly anonymous classes that can be garbage collected (https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/lang/invoke/MethodHandles.Lookup.html#defineHiddenClass(byte%5B%5D,boolean,java.lang.invoke.MethodHandles.Lookup.ClassOption https://docs.oracle.com/en/java/javase/22/docs/api/java.base......) ), but they are trickier to generate as they can’t have static fields (you don’t have a class name so have no way to refer to them) etc.
- layer8 2y agoSide note: You’re using the term “dereference” incorrectly (also in the article). It doesn’t mean “drop references”. It means “going from the reference to the thing being referenced”, or (in other words) “accessing the thing that is being referenced” [0]. It doesn’t mean the reference is going away. [0] https://en.wiktionary.org/wiki/dereference#Verb https://en.wiktionary.org/wiki/dereference#Verb
- ayewo 2y agoThanks for linking directly to the specific line number in the Compiler.java [1] code referenced in the original article. Not sure why they have that if statement that always evaluates to true: if(true)//!LOADER.isBound()) I usually prefer using the GitHub permalink [1] as it is easy for the line number to go out of sync. [1] https://github.com/clojure/clojure/blob/f376cf62bb0c30f72b0df4ee94c38fa503fa4be7/src/jvm/clojure/lang/Compiler.java#L7154 https://github.com/clojure/clojure/blob/f376cf62bb0c30f72b0d...