Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ConstantPool in .class file format

 
Robert Konigsberg
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I am writing a .class file parser (for fun) and I'm going through the specification for the class file format. Here's my question: So the ConstantPool spec has a list of elements. Some of the elements within the constant pool refer to other elements inside the pool.

Can I assume that if the nth element in the constant pool refers to the m'th element in the constant pool, then 0 <= m < n?

In other words:


Here: Element 1 refers to Element 0, so when I process element 1, I know that I can resolve Element 1 in my code.

But can *this* happen?


(It may not be reasonable, but can it??!
[ August 12, 2004: Message edited by: Robert Konigsberg ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume that "org.brainkandy.TestClass" is a constant of type CONSTANT_Class_info, while "UTF8: 0" is a constant of type CONSTANT_Utf8_info. In which case I believe you have it backwards. UTF8 structures do not refer to other constants; they just define strings. Period. But Class constants do refer to other constants; namely, to a UTF8 constant representing the (fully qualified) name of the class.

The spec doesn't say anything about whether a class constant can precede the UTF8 constant it references. Naively I would have guessed that usually it would not, however I just ran a test (using javap -verbose) and found that the class constants preceded the UTF8 constants they referenced. I would say that you cannot make any assumptions about this - a compiler may legitimately generate constants in any order it feels like.
 
Robert Konigsberg
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whoops, you're right. This stuff fries my mind a bit. I edited my original post to reflect your comments (you might like to remove your comment about "got it wrong")

But thanks for your comments. Once I fixed my error, it made more sense. But wah.

Rob
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you might like to remove your comment about "got it wrong"

Well, yeah, but then you'd need to edit your comment about my comment, and I'd have to edit this comment about your second comment. And nobody better add any other comments about this topic or we're really screwed.
 
Robert Konigsberg
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why does this sound like an episode of The Honeymooners?
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I find this thread very funny.

Hey, how about you delete this thread and start all over again?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic