src/share/vm/prims/jvmtiClassFileReconstituter.cpp

Print this page




 174   if (method->has_localvariable_table()) {
 175     local_variable_table_length = method->localvariable_table_length();
 176     ++attr_count;
 177     if (local_variable_table_length != 0) {
 178       // Compute the size of the local variable table attribute (VM stores raw):
 179       // LocalVariableTable_attribute {
 180       //   u2 attribute_name_index;
 181       //   u4 attribute_length;
 182       //   u2 local_variable_table_length;
 183       //   {
 184       //     u2 start_pc;
 185       //     u2 length;
 186       //     u2 name_index;
 187       //     u2 descriptor_index;
 188       //     u2 index;
 189       //   }
 190       attr_size += 2 + 4 + 2 + local_variable_table_length * (2 + 2 + 2 + 2 + 2);
 191     }
 192   }
 193 
 194   typeArrayHandle exception_table(thread(), const_method->exception_table());
 195   int exception_table_length = exception_table->length();
 196   int exception_table_entries = exception_table_length / 4;
 197   int code_size = const_method->code_size();
 198   int size =
 199     2+2+4 +                                // max_stack, max_locals, code_length
 200     code_size +                            // code
 201     2 +                                    // exception_table_length
 202     (2+2+2+2) * exception_table_entries +  // exception_table
 203     2 +                                    // attributes_count
 204     attr_size;                             // attributes
 205 
 206   write_attribute_name_index("Code");
 207   write_u4(size);
 208   write_u2(method->max_stack());
 209   write_u2(method->max_locals());
 210   write_u4(code_size);
 211   copy_bytecodes(method, (unsigned char*)writeable_address(code_size));
 212   write_u2(exception_table_entries);
 213   for (int index = 0; index < exception_table_length; ) {
 214     write_u2(exception_table->int_at(index++));
 215     write_u2(exception_table->int_at(index++));
 216     write_u2(exception_table->int_at(index++));
 217     write_u2(exception_table->int_at(index++));
 218   }
 219   write_u2(attr_count);
 220   if (line_num_cnt != 0) {
 221     write_line_number_table_attribute(method, line_num_cnt);
 222   }
 223   if (stackmap_len != 0) {
 224     write_stackmap_table_attribute(method, stackmap_len);
 225   }
 226   if (local_variable_table_length != 0) {
 227     write_local_variable_table_attribute(method, local_variable_table_length);
 228   }
 229 }
 230 
 231 // Write Exceptions attribute
 232 // JVMSpec|   Exceptions_attribute {
 233 // JVMSpec|     u2 attribute_name_index;
 234 // JVMSpec|     u4 attribute_length;
 235 // JVMSpec|     u2 number_of_exceptions;
 236 // JVMSpec|     u2 exception_index_table[number_of_exceptions];
 237 // JVMSpec|   }




 174   if (method->has_localvariable_table()) {
 175     local_variable_table_length = method->localvariable_table_length();
 176     ++attr_count;
 177     if (local_variable_table_length != 0) {
 178       // Compute the size of the local variable table attribute (VM stores raw):
 179       // LocalVariableTable_attribute {
 180       //   u2 attribute_name_index;
 181       //   u4 attribute_length;
 182       //   u2 local_variable_table_length;
 183       //   {
 184       //     u2 start_pc;
 185       //     u2 length;
 186       //     u2 name_index;
 187       //     u2 descriptor_index;
 188       //     u2 index;
 189       //   }
 190       attr_size += 2 + 4 + 2 + local_variable_table_length * (2 + 2 + 2 + 2 + 2);
 191     }
 192   }
 193 
 194   ExceptionTable exception_table(method());
 195   int exception_table_length = exception_table.length();

 196   int code_size = const_method->code_size();
 197   int size =
 198     2+2+4 +                                // max_stack, max_locals, code_length
 199     code_size +                            // code
 200     2 +                                    // exception_table_length
 201     (2+2+2+2) * exception_table_length +   // exception_table
 202     2 +                                    // attributes_count
 203     attr_size;                             // attributes
 204 
 205   write_attribute_name_index("Code");
 206   write_u4(size);
 207   write_u2(method->max_stack());
 208   write_u2(method->max_locals());
 209   write_u4(code_size);
 210   copy_bytecodes(method, (unsigned char*)writeable_address(code_size));
 211   write_u2(exception_table_length);
 212   for (int index = 0; index < exception_table_length; index++) {
 213     write_u2(exception_table.start_pc(index));
 214     write_u2(exception_table.end_pc(index));
 215     write_u2(exception_table.handler_pc(index));
 216     write_u2(exception_table.catch_type_index(index));
 217   }
 218   write_u2(attr_count);
 219   if (line_num_cnt != 0) {
 220     write_line_number_table_attribute(method, line_num_cnt);
 221   }
 222   if (stackmap_len != 0) {
 223     write_stackmap_table_attribute(method, stackmap_len);
 224   }
 225   if (local_variable_table_length != 0) {
 226     write_local_variable_table_attribute(method, local_variable_table_length);
 227   }
 228 }
 229 
 230 // Write Exceptions attribute
 231 // JVMSpec|   Exceptions_attribute {
 232 // JVMSpec|     u2 attribute_name_index;
 233 // JVMSpec|     u4 attribute_length;
 234 // JVMSpec|     u2 number_of_exceptions;
 235 // JVMSpec|     u2 exception_index_table[number_of_exceptions];
 236 // JVMSpec|   }