Javap Asciz Strings

A small question about the output generated by the command javapregarding a constant pool. When the javappool prints, it defines string constants as strings Asciz, which, as I understand it, means nullterminated Ascii:

const #20 = Asciz       hello world;

This would mean that the length of the string is unknown, and for parsing you will read every byte until you come across null.

However, the length of the constant string string constants of the pool is determined by two bytes preceding the string, and there is no added one null. ( Constant pool specification ).

Does it define javapstrings as Ascizor has a Ascizdifferent value that I don't know about?

+5
source share
2 answers

See bug # 6868539 . It is fixed in OpenJDK7, it javapis now printing Utf8.

+4
source

Constant # 20 is not a real string, but specific UTF8 characters used for your string. You probably have another constant, which is a string that refers to constant # 20. Asciz constants are used for things other than strings, such as field names, etc. Actual information contains UTF8 tag, length and bytes.

See http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html

0
source

All Articles