line number of a class file
when i use jdb with command "lines MyClass", i see jdb outputs line numbers of MyClass, which include line numbers of fields.
my Q is:
i am using c++ to open *.class file, but i can only find line numbers of method, i can not find line numbers of fields in the opened class buffer (i have doc of class-format).
according to sun's doc, there should be no line numbers for fields (i am not sure about this) inside a class file.
if this is true, how does jdb know line numbers of fields?
if not true, how to get line numbers of fields in a class file by reading its class-format?
thx
[624 byte] By [
soso999a] at [2007-9-29 18:15:29]

> when i use jdb with command "lines MyClass", i see jdb
> outputs line numbers of MyClass, which include line
> numbers of fields.
Fields... do the field declarations in your source
include an assignment? For example:
int i = 42;
When compiled into bytecodes, this will become:
Code:
0:bipush 42
2:istore_1
I suggest you write a simple class and compile it using
javac -g MyClass. Then disassemble the results
using javap -c -l MyClass and study the output.
For even more output, try:
javap -c -l -s -verbose MyClass
This will give you insight into how high level code
translates into the information that is preserved in
the .class file.
I forgot to mention section 4.7.8 The LineNumberTable Attribute
in this document:
http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#22856
The line number table is used to map BCI (Byte Code Index)
to lines of source code. There is one line number entry for a given
BCI (or some range of BCI, in most cases). But the same line number
may be applied to more than one BCI.
Consider a complex expression like:
if ((i > 0) && (java.lang.System.getProperty("verbose") != null) && (args.equals("-"))) { /* ... */ }
In this case, one source line translates into many bytecodes.