gtrak / no.disassemble

279 stars 13 forks source link

Make classes a WeakHashMap #4

Closed charles-dyfis-net closed 10 years ago

charles-dyfis-net commented 10 years ago

Code associated with a class should be GCable after that class is no longer in memory.

charles-dyfis-net commented 10 years ago

On investigation, I understand why the obvious thing isn't possible (the Class object doesn't exist yet).

Closing until a more practical implementation can be determined.

gtrak commented 10 years ago

This is a key problem with the design. I see a few options.

  1. Two maps, one with strings->bytes, another with WeakReferences from Class->bytes. Some kind of spin-loop or work queue to move entries from one to the other.
  2. Instrument the finalizers to clean up after themselves.
  3. Modify clojure's ephemeral classloaders to clean up after classes as they're unloaded using the agent transformer.

1 is probably the simplest.

charles-dyfis-net commented 10 years ago

The second option might get more straightforward than one might otherwise expect if assuming some changes I'd potentially like to make for other reasons (adding shimple support via soot).

gtrak commented 10 years ago

neat idea, one complication to think about, any classes not already in the JDK must be added to the JVM's bootclasspath via an uberjar, which means an extra build artifact and some more bits in the lein-plugin.

gtrak commented 10 years ago

also, I think adding non-trivial finalizers to everything would be slow at both load-time and unload-time. This might need a flag of some sort.