Hello Stephen,
Wednesday, June 11, 2003, 7:11:16 PM, you wrote:
SK> The code you sent is OK, at least for BCEL 5.0 and 5.1 (I have
SK> experience with those). The problem is elsewere.
I also used 5.0 and when saw exception switched to 5.1, but
exception is still here. :-(
SK> Btw, did you checked if your original (not instrumented) classes are
SK> acceptible? It is so stupid mistake, that you have to be genious to
SK> avoid it, at least I can not :))).
I tryied to post UUE with original class, but it seems, that UUE are
not accepted by mail list.
I am not sure, but I think, that original class itself is generated
directly in bytecode. It is EJB skeleton, generated by WebLogic. I
write profiler for Eclipse, it can handle almost all classes except
such already generated classes from WebLogic and CGLIB. For CGLIB I
don't have example, but for WebLogic I do.
I do try to check with _original_ class. And this exception ("Invalid
constant pool reference: 28088. Constant pool size is: 1024") appears
with it! I.e. I just load this class and create copy of each method
using MethodGen. I don't change code. Just copy, as you can see in
code. And even in this case I receive such exception. :-(
SK> Beside this: if you copy method from one class to another (i do not what
SK> are your real application), you must change the constant pool indices of
SK> the instructions.
In my test code I just copy code. Do I still need to make these
changes? Can you give me example?
SK> Konstantin Scheglov wrote:
>> I use following code to instrument one class.
>> But when I instrument some classes and try to print debug
>>information, I receive following exception.
>>
>>org.apache.bcel.classfile.ClassFormatException: Invalid constant pool reference:
>>28088. Constant pool size is: 1024
>> at org.apache.bcel.classfile.ConstantPool.getConstant(ConstantPool.java:242)
>> at org.apache.bcel.classfile.Utility.codeToString(Utility.java:369)
>> at org.apache.bcel.classfile.Utility.codeToString(Utility.java:166)
>> at org.apache.bcel.classfile.Code.toString(Code.java:326)
>> at org.apache.bcel.classfile.Code.toString(Code.java:352)
>> at java.lang.String.valueOf(String.java:2131)
>> at java.io.PrintStream.print(PrintStream.java:462)
>> at java.io.PrintStream.println(PrintStream.java:599)
>> at
>> ru.nlmk.eclipse.plugins.profiler.trace.Trace.instrumentClass(Trace.java:1190)
>> at
>> ru.nlmk.eclipse.plugins.profiler.trace.test.TestBCEL.main(TestBCEL.java:23)
>>
>>
>> As you can see, I just copy code from one method to another (in real application
>>I change code a little). And when I try to load this class in real application
>>I receive exception like this from JVM: "VerifyError: Illegal constant pool index".
>>
>>
>> public static JavaClass instrumentClass(JavaClass clazz) throws Exception {
>> ClassGen classGen = new ClassGen(clazz);
>> ConstantPoolGen cp = new ConstantPoolGen(clazz.getConstantPool());
>> classGen.setConstantPool(cp);
>> //
>> for (int i = 0; i < clazz.getMethods().length; i++) {
>> Method method = clazz.getMethods()[i];
>> if (method.isAbstract() || method.isNative())
>> continue;
>> if (method.getName().equals("finalize"))
>> continue;
>> MethodGen mg = new MethodGen(method, clazz.getClassName(),
>> cp);
>> mg.setConstantPool(cp);
>> Method newMethod = mg.getMethod();
>> if (m_Debug) {
>> System.out.println(method.getCode());
>> System.out.println(newMethod.getCode());
>> }
>> classGen.replaceMethod(method, newMethod);
>> }
>> //
>> JavaClass newClazz = classGen.getJavaClass();
>> newClazz.setConstantPool(cp.getFinalConstantPool());
>> return newClazz;
>> }
>>
>> What I do wrong?
>> I see such exception only on few classes (methods).
>> I have example of such class.
>>
>>
>>
>>
SK> ---------------------------------------------------------------------
SK> To unsubscribe, e-mail: [EMAIL PROTECTED]
SK> For additional commands, e-mail: [EMAIL PROTECTED]
--
Best regards,
Konstantin mailto:[EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]