src/share/vm/oops/constMethod.cpp

changeset 4572
927a311d00f9
parent 4497
16fb9f942703
child 4712
3efdfd6ddbf2
     1.1 --- a/src/share/vm/oops/constMethod.cpp	Fri Feb 08 16:56:03 2013 -0800
     1.2 +++ b/src/share/vm/oops/constMethod.cpp	Mon Feb 11 14:06:22 2013 -0500
     1.3 @@ -36,51 +36,26 @@
     1.4  
     1.5  ConstMethod* ConstMethod::allocate(ClassLoaderData* loader_data,
     1.6                                     int byte_code_size,
     1.7 -                                   int compressed_line_number_size,
     1.8 -                                   int localvariable_table_length,
     1.9 -                                   int exception_table_length,
    1.10 -                                   int checked_exceptions_length,
    1.11 -                                   int method_parameters_length,
    1.12 -                                   u2  generic_signature_index,
    1.13 +                                   InlineTableSizes* sizes,
    1.14                                     MethodType method_type,
    1.15                                     TRAPS) {
    1.16 -  int size = ConstMethod::size(byte_code_size,
    1.17 -                               compressed_line_number_size,
    1.18 -                               localvariable_table_length,
    1.19 -                               exception_table_length,
    1.20 -                               checked_exceptions_length,
    1.21 -                               method_parameters_length,
    1.22 -                               generic_signature_index);
    1.23 +  int size = ConstMethod::size(byte_code_size, sizes);
    1.24    return new (loader_data, size, true, THREAD) ConstMethod(
    1.25 -      byte_code_size, compressed_line_number_size, localvariable_table_length,
    1.26 -      exception_table_length, checked_exceptions_length,
    1.27 -      method_parameters_length, generic_signature_index,
    1.28 -      method_type, size);
    1.29 +      byte_code_size, sizes, method_type, size);
    1.30  }
    1.31  
    1.32  ConstMethod::ConstMethod(int byte_code_size,
    1.33 -                         int compressed_line_number_size,
    1.34 -                         int localvariable_table_length,
    1.35 -                         int exception_table_length,
    1.36 -                         int checked_exceptions_length,
    1.37 -                         int method_parameters_length,
    1.38 -                         u2  generic_signature_index,
    1.39 +                         InlineTableSizes* sizes,
    1.40                           MethodType method_type,
    1.41                           int size) {
    1.42  
    1.43    No_Safepoint_Verifier no_safepoint;
    1.44 -  set_interpreter_kind(Interpreter::invalid);
    1.45    init_fingerprint();
    1.46    set_constants(NULL);
    1.47    set_stackmap_data(NULL);
    1.48    set_code_size(byte_code_size);
    1.49    set_constMethod_size(size);
    1.50 -  set_inlined_tables_length(generic_signature_index,
    1.51 -                            checked_exceptions_length,
    1.52 -                            compressed_line_number_size,
    1.53 -                            localvariable_table_length,
    1.54 -                            exception_table_length,
    1.55 -                            method_parameters_length);
    1.56 +  set_inlined_tables_length(sizes);
    1.57    set_method_type(method_type);
    1.58    assert(this->size() == size, "wrong size for object");
    1.59  }
    1.60 @@ -88,47 +63,70 @@
    1.61  
    1.62  // Deallocate metadata fields associated with ConstMethod*
    1.63  void ConstMethod::deallocate_contents(ClassLoaderData* loader_data) {
    1.64 -  set_interpreter_kind(Interpreter::invalid);
    1.65    if (stackmap_data() != NULL) {
    1.66      MetadataFactory::free_array<u1>(loader_data, stackmap_data());
    1.67    }
    1.68    set_stackmap_data(NULL);
    1.69 +
    1.70 +  // deallocate annotation arrays
    1.71 +  if (has_method_annotations())
    1.72 +    MetadataFactory::free_array<u1>(loader_data, method_annotations());
    1.73 +  if (has_parameter_annotations())
    1.74 +    MetadataFactory::free_array<u1>(loader_data, parameter_annotations());
    1.75 +  if (has_type_annotations())
    1.76 +    MetadataFactory::free_array<u1>(loader_data, type_annotations());
    1.77 +  if (has_default_annotations())
    1.78 +    MetadataFactory::free_array<u1>(loader_data, default_annotations());
    1.79  }
    1.80  
    1.81  // How big must this constMethodObject be?
    1.82  
    1.83  int ConstMethod::size(int code_size,
    1.84 -                      int compressed_line_number_size,
    1.85 -                      int local_variable_table_length,
    1.86 -                      int exception_table_length,
    1.87 -                      int checked_exceptions_length,
    1.88 -                      int method_parameters_length,
    1.89 -                      u2  generic_signature_index) {
    1.90 +                      InlineTableSizes* sizes) {
    1.91    int extra_bytes = code_size;
    1.92 -  if (compressed_line_number_size > 0) {
    1.93 -    extra_bytes += compressed_line_number_size;
    1.94 +  if (sizes->compressed_linenumber_size() > 0) {
    1.95 +    extra_bytes += sizes->compressed_linenumber_size();
    1.96    }
    1.97 -  if (checked_exceptions_length > 0) {
    1.98 +  if (sizes->checked_exceptions_length() > 0) {
    1.99      extra_bytes += sizeof(u2);
   1.100 -    extra_bytes += checked_exceptions_length * sizeof(CheckedExceptionElement);
   1.101 +    extra_bytes += sizes->checked_exceptions_length() * sizeof(CheckedExceptionElement);
   1.102    }
   1.103 -  if (local_variable_table_length > 0) {
   1.104 +  if (sizes->localvariable_table_length() > 0) {
   1.105      extra_bytes += sizeof(u2);
   1.106      extra_bytes +=
   1.107 -              local_variable_table_length * sizeof(LocalVariableTableElement);
   1.108 +              sizes->localvariable_table_length() * sizeof(LocalVariableTableElement);
   1.109    }
   1.110 -  if (exception_table_length > 0) {
   1.111 +  if (sizes->exception_table_length() > 0) {
   1.112      extra_bytes += sizeof(u2);
   1.113 -    extra_bytes += exception_table_length * sizeof(ExceptionTableElement);
   1.114 +    extra_bytes += sizes->exception_table_length() * sizeof(ExceptionTableElement);
   1.115    }
   1.116 -  if (generic_signature_index != 0) {
   1.117 +  if (sizes->generic_signature_index() != 0) {
   1.118      extra_bytes += sizeof(u2);
   1.119    }
   1.120 -  if (method_parameters_length > 0) {
   1.121 +  if (sizes->method_parameters_length() > 0) {
   1.122      extra_bytes += sizeof(u2);
   1.123 -    extra_bytes += method_parameters_length * sizeof(MethodParametersElement);
   1.124 +    extra_bytes += sizes->method_parameters_length() * sizeof(MethodParametersElement);
   1.125    }
   1.126 +
   1.127 +  // Align sizes up to a word.
   1.128 +  extra_bytes = align_size_up(extra_bytes, BytesPerWord);
   1.129 +
   1.130 +  // One pointer per annotation array
   1.131 +  if (sizes->method_annotations_length() > 0) {
   1.132 +    extra_bytes += sizeof(AnnotationArray*);
   1.133 +  }
   1.134 +  if (sizes->parameter_annotations_length() > 0) {
   1.135 +    extra_bytes += sizeof(AnnotationArray*);
   1.136 +  }
   1.137 +  if (sizes->type_annotations_length() > 0) {
   1.138 +    extra_bytes += sizeof(AnnotationArray*);
   1.139 +  }
   1.140 +  if (sizes->default_annotations_length() > 0) {
   1.141 +    extra_bytes += sizeof(AnnotationArray*);
   1.142 +  }
   1.143 +
   1.144    int extra_words = align_size_up(extra_bytes, BytesPerWord) / BytesPerWord;
   1.145 +  assert(extra_words == extra_bytes/BytesPerWord, "should already be aligned");
   1.146    return align_object_size(header_size() + extra_words);
   1.147  }
   1.148  
   1.149 @@ -145,12 +143,28 @@
   1.150    return code_end();
   1.151  }
   1.152  
   1.153 +// Last short in ConstMethod* before annotations
   1.154 +u2* ConstMethod::last_u2_element() const {
   1.155 +  int offset = 0;
   1.156 +  if (has_method_annotations()) offset++;
   1.157 +  if (has_parameter_annotations()) offset++;
   1.158 +  if (has_type_annotations()) offset++;
   1.159 +  if (has_default_annotations()) offset++;
   1.160 +  return (u2*)((AnnotationArray**)constMethod_end() - offset) - 1;
   1.161 +}
   1.162 +
   1.163  u2* ConstMethod::generic_signature_index_addr() const {
   1.164    // Located at the end of the constMethod.
   1.165    assert(has_generic_signature(), "called only if generic signature exists");
   1.166    return last_u2_element();
   1.167  }
   1.168  
   1.169 +u2* ConstMethod::method_parameters_length_addr() const {
   1.170 +  assert(has_method_parameters(), "called only if table is present");
   1.171 +  return has_generic_signature() ? (last_u2_element() - 1) :
   1.172 +                                    last_u2_element();
   1.173 +}
   1.174 +
   1.175  u2* ConstMethod::checked_exceptions_length_addr() const {
   1.176    // Located immediately before the generic signature index.
   1.177    assert(has_checked_exceptions(), "called only if table is present");
   1.178 @@ -164,12 +178,6 @@
   1.179    }
   1.180  }
   1.181  
   1.182 -u2* ConstMethod::method_parameters_length_addr() const {
   1.183 -  assert(has_method_parameters(), "called only if table is present");
   1.184 -  return has_generic_signature() ? (last_u2_element() - 1) :
   1.185 -                                    last_u2_element();
   1.186 -}
   1.187 -
   1.188  u2* ConstMethod::exception_table_length_addr() const {
   1.189    assert(has_exception_handler(), "called only if table is present");
   1.190    if (has_checked_exceptions()) {
   1.191 @@ -181,9 +189,9 @@
   1.192        return (u2*)method_parameters_start() - 1;
   1.193      } else {
   1.194        // Else, the exception table is at the end of the constMethod.
   1.195 -    return has_generic_signature() ? (last_u2_element() - 1) :
   1.196 -                                      last_u2_element();
   1.197 -  }
   1.198 +      return has_generic_signature() ? (last_u2_element() - 1) :
   1.199 +                                        last_u2_element();
   1.200 +    }
   1.201    }
   1.202  }
   1.203  
   1.204 @@ -204,32 +212,38 @@
   1.205          // Else, the exception table is at the end of the constMethod.
   1.206        return has_generic_signature() ? (last_u2_element() - 1) :
   1.207                                          last_u2_element();
   1.208 +      }
   1.209      }
   1.210    }
   1.211 -  }
   1.212  }
   1.213  
   1.214  // Update the flags to indicate the presence of these optional fields.
   1.215 -void ConstMethod::set_inlined_tables_length(u2  generic_signature_index,
   1.216 -                                            int checked_exceptions_len,
   1.217 -                                            int compressed_line_number_size,
   1.218 -                                            int localvariable_table_len,
   1.219 -                                            int exception_table_len,
   1.220 -                                            int method_parameters_len) {
   1.221 -  assert(_flags == 0, "Error");
   1.222 -  if (compressed_line_number_size > 0)
   1.223 +void ConstMethod::set_inlined_tables_length(InlineTableSizes* sizes) {
   1.224 +  _flags = 0;
   1.225 +  if (sizes->compressed_linenumber_size() > 0)
   1.226      _flags |= _has_linenumber_table;
   1.227 -  if (generic_signature_index != 0)
   1.228 +  if (sizes->generic_signature_index() != 0)
   1.229      _flags |= _has_generic_signature;
   1.230 -  if (method_parameters_len > 0)
   1.231 +  if (sizes->method_parameters_length() > 0)
   1.232      _flags |= _has_method_parameters;
   1.233 -  if (checked_exceptions_len > 0)
   1.234 +  if (sizes->checked_exceptions_length() > 0)
   1.235      _flags |= _has_checked_exceptions;
   1.236 -  if (exception_table_len > 0)
   1.237 +  if (sizes->exception_table_length() > 0)
   1.238      _flags |= _has_exception_table;
   1.239 -  if (localvariable_table_len > 0)
   1.240 +  if (sizes->localvariable_table_length() > 0)
   1.241      _flags |= _has_localvariable_table;
   1.242  
   1.243 +  // annotations, they are all pointer sized embedded objects so don't have
   1.244 +  // a length embedded also.
   1.245 +  if (sizes->method_annotations_length() > 0)
   1.246 +    _flags |= _has_method_annotations;
   1.247 +  if (sizes->parameter_annotations_length() > 0)
   1.248 +    _flags |= _has_parameter_annotations;
   1.249 +  if (sizes->type_annotations_length() > 0)
   1.250 +    _flags |= _has_type_annotations;
   1.251 +  if (sizes->default_annotations_length() > 0)
   1.252 +    _flags |= _has_default_annotations;
   1.253 +
   1.254    // This code is extremely brittle and should possibly be revised.
   1.255    // The *_length_addr functions walk backwards through the
   1.256    // constMethod data, using each of the length indexes ahead of them,
   1.257 @@ -242,17 +256,17 @@
   1.258    // Also, the servicability agent needs to be informed anytime
   1.259    // anything is added here.  It might be advisable to have some sort
   1.260    // of indication of this inline.
   1.261 -  if (generic_signature_index != 0)
   1.262 -    *(generic_signature_index_addr()) = generic_signature_index;
   1.263 +  if (sizes->generic_signature_index() != 0)
   1.264 +    *(generic_signature_index_addr()) = sizes->generic_signature_index();
   1.265    // New data should probably go here.
   1.266 -  if (method_parameters_len > 0)
   1.267 -    *(method_parameters_length_addr()) = method_parameters_len;
   1.268 -  if (checked_exceptions_len > 0)
   1.269 -    *(checked_exceptions_length_addr()) = checked_exceptions_len;
   1.270 -  if (exception_table_len > 0)
   1.271 -    *(exception_table_length_addr()) = exception_table_len;
   1.272 -  if (localvariable_table_len > 0)
   1.273 -    *(localvariable_table_length_addr()) = localvariable_table_len;
   1.274 +  if (sizes->method_parameters_length() > 0)
   1.275 +    *(method_parameters_length_addr()) = sizes->method_parameters_length();
   1.276 +  if (sizes->checked_exceptions_length() > 0)
   1.277 +    *(checked_exceptions_length_addr()) = sizes->checked_exceptions_length();
   1.278 +  if (sizes->exception_table_length() > 0)
   1.279 +    *(exception_table_length_addr()) = sizes->exception_table_length();
   1.280 +  if (sizes->localvariable_table_length() > 0)
   1.281 +    *(localvariable_table_length_addr()) = sizes->localvariable_table_length();
   1.282  }
   1.283  
   1.284  int ConstMethod::method_parameters_length() const {
   1.285 @@ -307,6 +321,34 @@
   1.286    return (ExceptionTableElement*)addr;
   1.287  }
   1.288  
   1.289 +AnnotationArray** ConstMethod::method_annotations_addr() const {
   1.290 +  assert(has_method_annotations(), "should only be called if method annotations are present");
   1.291 +  return (AnnotationArray**)constMethod_end() - 1;
   1.292 +}
   1.293 +
   1.294 +AnnotationArray** ConstMethod::parameter_annotations_addr() const {
   1.295 +  assert(has_parameter_annotations(), "should only be called if method parameter annotations are present");
   1.296 +  int offset = 1;
   1.297 +  if (has_method_annotations()) offset++;
   1.298 +  return (AnnotationArray**)constMethod_end() - offset;
   1.299 +}
   1.300 +
   1.301 +AnnotationArray** ConstMethod::type_annotations_addr() const {
   1.302 +  assert(has_type_annotations(), "should only be called if method type annotations are present");
   1.303 +  int offset = 1;
   1.304 +  if (has_method_annotations()) offset++;
   1.305 +  if (has_parameter_annotations()) offset++;
   1.306 +  return (AnnotationArray**)constMethod_end() - offset;
   1.307 +}
   1.308 +
   1.309 +AnnotationArray** ConstMethod::default_annotations_addr() const {
   1.310 +  assert(has_default_annotations(), "should only be called if method default annotations are present");
   1.311 +  int offset = 1;
   1.312 +  if (has_method_annotations()) offset++;
   1.313 +  if (has_parameter_annotations()) offset++;
   1.314 +  if (has_type_annotations()) offset++;
   1.315 +  return (AnnotationArray**)constMethod_end() - offset;
   1.316 +}
   1.317  
   1.318  // Printing
   1.319  
   1.320 @@ -339,8 +381,25 @@
   1.321    sz->_bytecode_bytes     += (n2 = code_size());
   1.322    sz->_stackmap_bytes     += (n3 = sz->count_array(stackmap_data()));
   1.323  
   1.324 -  sz->_method_all_bytes += n1 + n3; // note: n2 is part of n3
   1.325 -  sz->_ro_bytes += n1 + n3;
   1.326 +  // Count method annotations
   1.327 +  int a1 = 0, a2 = 0, a3 = 0, a4 = 0;
   1.328 +  if (has_method_annotations()) {
   1.329 +    sz->_methods_annotations_bytes += (a1 = sz->count_array(method_annotations()));
   1.330 +  }
   1.331 +  if (has_parameter_annotations()) {
   1.332 +    sz->_methods_parameter_annotations_bytes += (a2 = sz->count_array(parameter_annotations()));
   1.333 +  }
   1.334 +  if (has_type_annotations()) {
   1.335 +    sz->_methods_type_annotations_bytes += (a3 = sz->count_array(type_annotations()));
   1.336 +  }
   1.337 +  if (has_default_annotations()) {
   1.338 +    sz->_methods_default_annotations_bytes += (a4 = sz->count_array(default_annotations()));
   1.339 +  }
   1.340 +
   1.341 +  int size_annotations = a1 + a2 + a3 + a4;
   1.342 +
   1.343 +  sz->_method_all_bytes += n1 + n3 + size_annotations; // note: n2 is part of n3
   1.344 +  sz->_ro_bytes += n1 + n3 + size_annotations;
   1.345  }
   1.346  #endif // INCLUDE_SERVICES
   1.347  
   1.348 @@ -352,10 +411,9 @@
   1.349  
   1.350    // Verification can occur during oop construction before the method or
   1.351    // other fields have been initialized.
   1.352 -  guarantee(is_metadata(), err_msg("Should be metadata " PTR_FORMAT, this));
   1.353    guarantee(method()->is_method(), "should be method");
   1.354  
   1.355 -  address m_end = (address)((oop*) this + size());
   1.356 +  address m_end = (address)((intptr_t) this + size());
   1.357    address compressed_table_start = code_end();
   1.358    guarantee(compressed_table_start <= m_end, "invalid method layout");
   1.359    address compressed_table_end = compressed_table_start;

mercurial