JVM Knowledge

The LineNumberTable attribute is an optional variable-length attribute in the attributes table of a Code attribute (§4.7.3). It may be used by debuggers to determine which part of the code array corresponds to a given line number in the original source file.

If multiple LineNumberTable attributes are present in the attributes table of a Code attribute, then they may appear in any order.

There may be more than one LineNumberTable attribute per line of a source file in the attributes table of a Code attribute. That is, LineNumberTable attributes may together represent a given line of a source file, and need not be one-to-one with source lines.

The LineNumberTable attribute has the following format:

LineNumberTable_attribute {
    u2 attribute_name_index;
    u4 attribute_length;
    u2 line_number_table_length;
    {   u2 start_pc;
        u2 line_number;
    } line_number_table[line_number_table_length];
}

The items of the LineNumberTable_attribute structure are as follows:

  • attribute_name_index

    The value of the attribute_name_index item must be a valid index into the constant_pool table. The constant_pool entry at that index must be a CONSTANT_Utf8_info structure (§4.4.7) representing the string "LineNumberTable".

  • attribute_length

    The value of the attribute_length item indicates the length of the attribute, excluding the initial six bytes.

  • line_number_table_length

    The value of the line_number_table_length item indicates the number of entries in the line_number_table array.

  • line_number_table[]

    Each entry in the line_number_table array indicates that the line number in the original source file changes at a given point in the code array. Each line_number_table entry must contain the following two items:

    • start_pc

      The value of the start_pc item must indicate the index into the code array at which the code for a new line in the original source file begins.

      The value of start_pc must be less than the value of the code_length item of the Code attribute of which this LineNumberTable is an attribute.

    • line_number

      The value of the line_number item must give the corresponding line number in the original source file.