Hi, Thank you for your reply, Actually I have located the class file, it's inside a file named rt.jar It's seem like I can build a new StringBuilder class which extends from the original with some new method, update the new class into rt.jar and Java still works pretty well. I can use the new methods from StringBuilder
There's still one important issue, if I try to use ASM, to probe for any special signature in any native class, for example java.lang.String then insert a few bytecodes which will invoke static to the newly created method inside java.lang.StringBuilder. The result is the JVM will crash each time it starts up with message: # A fatal error has been detected by the Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00000000, pid=7356, tid=1576 # # JRE version: 6.0_17-b04 # Java VM: Java HotSpot(TM) Client VM (14.3-b01 mixed mode windows-x86 ) # Problematic frame: # C 0x00000000 The ASM code works perfectly well with non-native classes, Is there hint for this issue ? Thank you Bhm > Date: Tue, 5 Jul 2011 17:51:06 +0400 > From: [email protected] > To: [email protected] > CC: [email protected] > Subject: Re: inject bytecode into java native classes > > 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 ...
