Hi! Thank you for helping me. I know that it doesn't work because the new code should print a message on the screen (Par = 1, ... ). And the message doesn't appear! I'm sending you the code of the example that I'm working on. Some things are written in Portuguese, but I don't think it will be a problem... :) The class that I want to modify is "Fila". "AcessoFila" access it (is the "test case"), and "Monitor" modifies it. The change that I want to make in "Fila" in load-time is include a call (comment in the line 22). If you take off the comment and runs it, you will see the difference.
Thanks again! ----- Original Message ----- From: "Steven Smith" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, February 10, 2004 1:07 PM Subject: FW: The changes don't work > Hopefully you've subscribed to the list and you've got this already. If > not, you may want to subscribe to the various BCEL mailing lists. > > -----Original Message----- > From: Steven Smith [mailto:[EMAIL PROTECTED] > Sent: Tuesday, February 10, 2004 10:03 AM > To: 'BCEL Users List' > Subject: RE: The changes don't work > > > I don't see a problem with the code you included. The numbers after the > lines are (I *believe*) the constant pool indexes of the various constants > and this shouldn't affect the execution of your program. > > Could you explain what you mean by "it doesn't work"? Do you get an > exception, error message, etc.? Also, if you could post the complete source > or a reproducible test case that would help. > > -----Original Message----- > From: Camila Rocha [mailto:[EMAIL PROTECTED] > Sent: Tuesday, February 10, 2004 8:55 AM > To: [EMAIL PROTECTED] > Subject: The changes don't work > > > Hello, > > I am a beginner, and I have a doubt... I want to modify an existing class. > So, I used BCELifier to generate the code of the class, and then tried to > used it to modify my class. > The modification is a call to a static method called > Monitor.incluirTraceEstado(String), passing ("Par = " + par) as a parameter > (par is int private attribute). > When I insert the call in the source code, without using BCEL, the code of > the method that calls de static method is this (just the beginning): > > Code(max_stack = 3, max_locals = 3, code_length = 88) > 0: new <java.lang.StringBuffer> (6) > 3: dup > 4: invokespecial java.lang.StringBuffer.<init> ()V (7) > 7: ldc "Par = " (8) > 9: invokevirtual java.lang.StringBuffer.append > (Ljava/lang/String;)Ljava/lang/StringBuffer; (9) > 12: iload_1 > 13: invokevirtual java.lang.StringBuffer.append > (I)Ljava/lang/StringBuffer; (10) > 16: invokevirtual java.lang.StringBuffer.toString ()Ljava/lang/String; > (11) > 19: invokestatic Monitor.incluirTraceEstado (Ljava/lang/String;)V > (12) > 22: aload_0 > 23: getfield Fila.vetor_par [I (2) > 26: aload_0 > 27: getfield Fila.ipar I (4) > > > But, when I insert it using BCEL, the code is this (lines 0 to 19 are new). > It's almost the same, the differences are some number in lines 7 and 19. And > it doesn't work! > > 0: new <java.lang.StringBuffer> (7) > 3: dup > 4: invokespecial java.lang.StringBuffer.<init> ()V (8) > 7: ldc "Par = " (76) > 9: invokevirtual java.lang.StringBuffer.append > (Ljava/lang/String;)Ljava/lang/StringBuffer; (10) > 12: iload_1 > 13: invokevirtual java.lang.StringBuffer.append > (I)Ljava/lang/StringBuffer; (11) > 16: invokevirtual java.lang.StringBuffer.toString ()Ljava/lang/String; > (13) > 19: invokestatic Monitor.incluirTraceEstado (Ljava/lang/String;)V > (74) > 22: aload_0 > 23: getfield Fila.vetor_par [I (2) > 26: aload_0 > 27: getfield Fila.ipar I (4) > > My question is: what are these numbers? Are they causing the problem? How > can I fix this code? The BCEL code that I wrote to create it is: (I'm > inserting the last instruction first, and so on... ) > > JavaClass clazz = Repository.lookupClass("Fila"); > Method[] methods = clazz.getMethods(); > ConstantPoolGen cp = new ConstantPoolGen(clazz.getConstantPool()); > MethodGen mg = new MethodGen(methods[1], clazz.getClassName(), cp); > InstructionList il = mg.getInstructionList(); > InstructionFactory factory = new InstructionFactory(cp); > il.insert(factory.createInvoke("Monitor", "incluirTraceEstado", Type.VOID, > new Type[] { Type.STRING }, (short)184)); > il.insert(factory.createInvoke("java.lang.StringBuffer", "toString", > Type.STRING, Type.NO_ARGS, (short)182)); > il.insert(factory.createInvoke("java.lang.StringBuffer", "append", > Type.STRINGBUFFER, new Type[] { Type.INT }, (short)182)); > il.insert(factory.createLoad(Type.INT, 1)); > il.insert(factory.createInvoke("java.lang.StringBuffer", "append", > Type.STRINGBUFFER, new Type[] { Type.STRING }, (short)182)); > il.insert(new PUSH(cp, "Par = ")); > il.insert(factory.createInvoke("java.lang.StringBuffer", "<init>", > Type.VOID, Type.NO_ARGS, (short)183)); > il.insert(InstructionConstants.DUP); > InstructionHandle ih_0 = > il.insert(factory.createNew("java.lang.StringBuffer")); > methods[1] = mg.getMethod(); > > Sorry about the huge email and my poor English! I'll be very glad with some > help. > > Thanks! > > Camila Rocha > ------------------------------------------------------------------------ > Master Student in Computer Science > Institute of Computing - UNICAMP - Brazil > www.ic.unicamp.br/~ra022247 > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
