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 ...

Reply via email to