title: Possible to get native performance for dynamically compiled code that can be unloaded?
body: <p>In <a href="https://stackoverflow.com/q/31040998/709537">.Net, it seems</a> you cannot</p>
  
  <ol>
  <li>dynamically compile code</li>
  <li>call the compiled code directly (i.e. w/o "remoting", marshaling, etc) <strong>and</strong></li>
  <li>remove (only) the compiled code from memory</li>
  </ol>
  
  <p>You have to decide between 2. (by generating the code into the calling AppDomain itself) or 3. (by generating the code into a throw-away AppDomain), but you cannot have both.</p>
  
  <p>Now I'm curious if this is possible in Java. I don't know enough about ClassLoaders, but it seems in Java I could</p>
  
  <ol>
  <li>dynamically compile code into a throw-away class loader</li>
  <li>call the compiled code (say, through a virtual method call to predefined interface) directly, w/o any marshaling</li>
  <li>remove all references to compiled class and throw-away class loader so GC will take care of removal</li>
  </ol>
  
  <p>Is that assumption valid?</p>