I haven't actually done it, but this sounds like on-the-fly instrumentation should be doable with the Matlab IDE and JaCoCo.
EclEmma is for running things specifically from Eclipse; for Matlab you might want to use JaCoCo on its own even for online analysis. Maybe by using its Java Agent, which you could get Matlab to load into its embedded JVM by supplying a custom java.opts
file in your startup directory which includes the -javaagent:...
option to load in JaCoCo, described in that linked page.
If you stick your Java classes on Matlab's static Java classpath, as opposed to the dynamic one, they'll be loaded through the regular Java system class loaders instead of the custom Matlab one, and should be available to regular Java code coverage tools. Those custom Matlab classloaders are only for classes on the "dynamic" Matlab Java classpath. You can do this by providing a custom javaclasspath.txt
file in your pref or startup directory or by using a ClassPath hacker tool. (See "Bringing Java Classes into Matlab Workspace" for some details, and this other question about static vs dynamic Java classpath manipulation.)
And depending on how JaCoCo hooks into the JVM, you could probably point it at the custom Matlab classloaders, too – they're URL classloaders, and you can get at the objects for them using Java Reflection from within a Matlab session. The JaCoCo documentation (in "Mission") seems to suggest that using the JaCoCo API, instead of a normal invocation, will let you work with custom class loaders.