java - Possible to get native performance for dynamically compiled code that can be unloaded? -


in .net, seems cannot

  1. dynamically compile code
  2. call compiled code directly (i.e. w/o "remoting", marshaling, etc) and
  3. remove (only) compiled code memory

you have decide between 2. (by generating code calling appdomain itself) or 3. (by generating code throw-away appdomain), cannot have both.

now i'm curious if possible in java. don't know enough classloaders, seems in java could

  1. dynamically compile code throw-away class loader
  2. call compiled code (say, through virtual method call predefined interface) directly, w/o marshaling
  3. remove references compiled class , throw-away class loader gc take care of removal

is assumption valid?

yes, can compile / load class code away class loader, call without issue.

yes, dynamically code reach 'full performance'. there no difference. however, newly loaded code start in interpreted mode , needs warm before compiled.

however, point 3. tricky.

  • 'leaking' throw away class loader easy / likely. class loader keeps references it's loaded classes. each class holds reference it's classloader. each object reference it's class. therefore, long have reference object or class loaded throw away class loader, , it's loaded classes stay alive. because easy have reference object, 'classloader' leaks common.
  • it depends on gc configuration , jvm version gc passes on over loaded classes. might need flags enable it. cms gc '-xx:+cmsclassunloadingenabled'.
  • there code cache (in openjdk/hotspot), keeps compiled code. if keep loading code through you're app's lifetime, might overrun cache. in older jvm's filled up, , once full, stopped compiling code, degrading in performance, unless enabled flushing cache (-xx:+usecodecacheflushing). afaik in newer releases flushes default. double check it. might want keep eye on code cache. (via jmx example)

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -