inject bytecode into java native classes

Dmitry Samersoff Dmitry.Samersoff at oracle.com
Tue Jul 5 06:51:06 PDT 2011


On 2011-07-05 16:37, Lee Ming wrote:
> Hi,
>
> I'm trying to do some experiment with the native classes, for example
> java.lang.StringBuilder.
> I intend to inject some bytecodes into the class, but I could not find
> the location of the class
> file. Anyone can point out ?

see below (error handling is omitted)

         clz = Class.forName(p_className.replace('/', '.'));
         ClassLoader loader = ProfilerAgent.class.getClassLoader();
         URL classURL = loader.getResource(p_className + ".class");

         InputStream fis;

         if (classURL.getProtocol().equals("file")) {
             File f = new File(classURL.getFile());
             fis = new FileInputStream(f);
         } else {
             URLConnection conn = classURL.openConnection();
             fis = conn.getInputStream();
         }

Then use ASM to do instrumentation.

-- 
Dmitry Samersoff
Java Hotspot development team, SPB04
* There will come soft rains ...


More information about the serviceability-dev mailing list