jakarta-bcel-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maithily mundle <mun...@cs.orst.edu>
Subject Adding instructions to the byte code
Date Fri, 01 Nov 2002 02:30:18 GMT
I am a grad student in Oregon State University. I was trying to play with
BCEL library and now I am stuck at one point, I hope you can help me
out. I was trying to add some instructions to the class file and update
the class file. I was trying to generate the simple code.

My original file looks like this

import java.io.*;

public class cl{
	public static void main(String[] args){
		System.out.println("Hello");
	}

}

I was trying to change it to

import java.io.*;

public class cl{
	public static void main(String[] args){
		int i = 5;
		i=i+1;
		System.out.println(i);
		System.out.println("Hello");
	}

}

I have succeeded in doing that, I mean adding instructions, But I could
not change the constant pool, So my new class file is not executing.
Here are the constant pool entries for my code and the one that I should
have generated after updating the class file

My constant pool

(1)CONSTANT_Methodref[10](class_index = 6, name_and_type_index = 15)
(2)CONSTANT_Fieldref[9](class_index = 16, name_and_type_index = 17)
(3)CONSTANT_String[8](string_index = 18)
(4)CONSTANT_Methodref[10](class_index = 19, name_and_type_index = 20)
(5)CONSTANT_Class[7](name_index = 21)
(6)CONSTANT_Class[7](name_index = 22)
(7)CONSTANT_Utf8[1]("<init>")
(8)CONSTANT_Utf8[1]("()V")
(9)CONSTANT_Utf8[1]("Code")
(10)CONSTANT_Utf8[1]("LineNumberTable")
(11)CONSTANT_Utf8[1]("main")
(12)CONSTANT_Utf8[1]("([Ljava/lang/String;)V")
(13)CONSTANT_Utf8[1]("SourceFile")
(14)CONSTANT_Utf8[1]("cl.java")
(15)CONSTANT_NameAndType[12](name_index = 7, signature_index = 8)
(16)CONSTANT_Class[7](name_index = 23)
(17)CONSTANT_NameAndType[12](name_index = 24, signature_index = 25)
(18)CONSTANT_Utf8[1]("Hello")
(19)CONSTANT_Class[7](name_index = 26)
(20)CONSTANT_NameAndType[12](name_index = 27, signature_index = 28)
(21)CONSTANT_Utf8[1]("cl")
(22)CONSTANT_Utf8[1]("java/lang/Object")
(23)CONSTANT_Utf8[1]("java/lang/System")
(24)CONSTANT_Utf8[1]("out")
(25)CONSTANT_Utf8[1]("Ljava/io/PrintStream;")
(26)CONSTANT_Utf8[1]("java/io/PrintStream")
(27)CONSTANT_Utf8[1]("println")
(28)CONSTANT_Utf8[1]("(Ljava/lang/String;)V")

Required constant pool

1)CONSTANT_Methodref[10](class_index = 7, name_and_type_index = 16)
2)CONSTANT_Fieldref[9](class_index = 17, name_and_type_index = 18)
3)CONSTANT_Methodref[10](class_index = 19, name_and_type_index = 20)
4)CONSTANT_String[8](string_index = 21)
5)CONSTANT_Methodref[10](class_index = 19, name_and_type_index = 22)
6)CONSTANT_Class[7](name_index = 23)
7)CONSTANT_Class[7](name_index = 24)
8)CONSTANT_Utf8[1]("<init>")
9)CONSTANT_Utf8[1]("()V")
10)CONSTANT_Utf8[1]("Code")
11)CONSTANT_Utf8[1]("LineNumberTable")
12)CONSTANT_Utf8[1]("main")
13)CONSTANT_Utf8[1]("([Ljava/lang/String;)V")
14)CONSTANT_Utf8[1]("SourceFile")
15)CONSTANT_Utf8[1]("cl.java")
16)CONSTANT_NameAndType[12](name_index = 8, signature_index = 9)
17)CONSTANT_Class[7](name_index = 25)
18)CONSTANT_NameAndType[12](name_index = 26, signature_index = 27)
19)CONSTANT_Class[7](name_index = 28)
20)CONSTANT_NameAndType[12](name_index = 29, signature_index = 30)
21)CONSTANT_Utf8[1]("Hello")
22)CONSTANT_NameAndType[12](name_index = 29, signature_index = 31)
23)CONSTANT_Utf8[1]("cl")
24)CONSTANT_Utf8[1]("java/lang/Object")
25)CONSTANT_Utf8[1]("java/lang/System")
26)CONSTANT_Utf8[1]("out")
27)CONSTANT_Utf8[1]("Ljava/io/PrintStream;")
28)CONSTANT_Utf8[1]("java/io/PrintStream")
29)CONSTANT_Utf8[1]("println")
30)CONSTANT_Utf8[1]("(I)V")
31)CONSTANT_Utf8[1]("(Ljava/lang/String;)V")

Can you plase tell me how to update the constant pool to make my new class
file work?

Maithily Mundle,
CS Department,
OSU.



--
To unsubscribe, e-mail:   <mailto:bcel-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:bcel-user-help@jakarta.apache.org>


Mime
View raw message