src/share/vm/oops/constMethod.cpp

Wed, 13 Mar 2013 09:10:35 -0400

author
coleenp
date
Wed, 13 Mar 2013 09:10:35 -0400
changeset 4715
5939f5953b45
parent 4712
3efdfd6ddbf2
child 4719
c8b31b461e1a
permissions
-rw-r--r--

8009836: nsk/regression/b4222717 fails with empty stack trace
Summary: Some zeroing was missed for bug 8003553, causing empty stack traces and Xcom crashes, add back zeroing to metablock
Reviewed-by: dholmes, rbackman

     1 /*
     2  * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #include "precompiled.hpp"
    26 #include "interpreter/interpreter.hpp"
    27 #include "memory/gcLocker.hpp"
    28 #include "memory/heapInspection.hpp"
    29 #include "memory/metadataFactory.hpp"
    30 #include "oops/constMethod.hpp"
    31 #include "oops/method.hpp"
    33 // Static initialization
    34 const u2 ConstMethod::MAX_IDNUM   = 0xFFFE;
    35 const u2 ConstMethod::UNSET_IDNUM = 0xFFFF;
    37 ConstMethod* ConstMethod::allocate(ClassLoaderData* loader_data,
    38                                    int byte_code_size,
    39                                    InlineTableSizes* sizes,
    40                                    MethodType method_type,
    41                                    TRAPS) {
    42   int size = ConstMethod::size(byte_code_size, sizes);
    43   return new (loader_data, size, true, THREAD) ConstMethod(
    44       byte_code_size, sizes, method_type, size);
    45 }
    47 ConstMethod::ConstMethod(int byte_code_size,
    48                          InlineTableSizes* sizes,
    49                          MethodType method_type,
    50                          int size) {
    52   No_Safepoint_Verifier no_safepoint;
    53   init_fingerprint();
    54   set_constants(NULL);
    55   set_stackmap_data(NULL);
    56   set_code_size(byte_code_size);
    57   set_constMethod_size(size);
    58   set_inlined_tables_length(sizes); // sets _flags
    59   set_method_type(method_type);
    60   assert(this->size() == size, "wrong size for object");
    61   set_name_index(0);
    62   set_signature_index(0);
    63   set_constants(NULL);
    64   set_max_stack(0);
    65   set_max_locals(0);
    66   set_method_idnum(0);
    67   set_size_of_parameters(0);
    68 }
    71 // Deallocate metadata fields associated with ConstMethod*
    72 void ConstMethod::deallocate_contents(ClassLoaderData* loader_data) {
    73   if (stackmap_data() != NULL) {
    74     MetadataFactory::free_array<u1>(loader_data, stackmap_data());
    75   }
    76   set_stackmap_data(NULL);
    78   // deallocate annotation arrays
    79   if (has_method_annotations())
    80     MetadataFactory::free_array<u1>(loader_data, method_annotations());
    81   if (has_parameter_annotations())
    82     MetadataFactory::free_array<u1>(loader_data, parameter_annotations());
    83   if (has_type_annotations())
    84     MetadataFactory::free_array<u1>(loader_data, type_annotations());
    85   if (has_default_annotations())
    86     MetadataFactory::free_array<u1>(loader_data, default_annotations());
    87 }
    89 // How big must this constMethodObject be?
    91 int ConstMethod::size(int code_size,
    92                       InlineTableSizes* sizes) {
    93   int extra_bytes = code_size;
    94   if (sizes->compressed_linenumber_size() > 0) {
    95     extra_bytes += sizes->compressed_linenumber_size();
    96   }
    97   if (sizes->checked_exceptions_length() > 0) {
    98     extra_bytes += sizeof(u2);
    99     extra_bytes += sizes->checked_exceptions_length() * sizeof(CheckedExceptionElement);
   100   }
   101   if (sizes->localvariable_table_length() > 0) {
   102     extra_bytes += sizeof(u2);
   103     extra_bytes +=
   104               sizes->localvariable_table_length() * sizeof(LocalVariableTableElement);
   105   }
   106   if (sizes->exception_table_length() > 0) {
   107     extra_bytes += sizeof(u2);
   108     extra_bytes += sizes->exception_table_length() * sizeof(ExceptionTableElement);
   109   }
   110   if (sizes->generic_signature_index() != 0) {
   111     extra_bytes += sizeof(u2);
   112   }
   113   if (sizes->method_parameters_length() > 0) {
   114     extra_bytes += sizeof(u2);
   115     extra_bytes += sizes->method_parameters_length() * sizeof(MethodParametersElement);
   116   }
   118   // Align sizes up to a word.
   119   extra_bytes = align_size_up(extra_bytes, BytesPerWord);
   121   // One pointer per annotation array
   122   if (sizes->method_annotations_length() > 0) {
   123     extra_bytes += sizeof(AnnotationArray*);
   124   }
   125   if (sizes->parameter_annotations_length() > 0) {
   126     extra_bytes += sizeof(AnnotationArray*);
   127   }
   128   if (sizes->type_annotations_length() > 0) {
   129     extra_bytes += sizeof(AnnotationArray*);
   130   }
   131   if (sizes->default_annotations_length() > 0) {
   132     extra_bytes += sizeof(AnnotationArray*);
   133   }
   135   int extra_words = align_size_up(extra_bytes, BytesPerWord) / BytesPerWord;
   136   assert(extra_words == extra_bytes/BytesPerWord, "should already be aligned");
   137   return align_object_size(header_size() + extra_words);
   138 }
   140 Method* ConstMethod::method() const {
   141     return _constants->pool_holder()->method_with_idnum(_method_idnum);
   142   }
   144 // linenumber table - note that length is unknown until decompression,
   145 // see class CompressedLineNumberReadStream.
   147 u_char* ConstMethod::compressed_linenumber_table() const {
   148   // Located immediately following the bytecodes.
   149   assert(has_linenumber_table(), "called only if table is present");
   150   return code_end();
   151 }
   153 // Last short in ConstMethod* before annotations
   154 u2* ConstMethod::last_u2_element() const {
   155   int offset = 0;
   156   if (has_method_annotations()) offset++;
   157   if (has_parameter_annotations()) offset++;
   158   if (has_type_annotations()) offset++;
   159   if (has_default_annotations()) offset++;
   160   return (u2*)((AnnotationArray**)constMethod_end() - offset) - 1;
   161 }
   163 u2* ConstMethod::generic_signature_index_addr() const {
   164   // Located at the end of the constMethod.
   165   assert(has_generic_signature(), "called only if generic signature exists");
   166   return last_u2_element();
   167 }
   169 u2* ConstMethod::method_parameters_length_addr() const {
   170   assert(has_method_parameters(), "called only if table is present");
   171   return has_generic_signature() ? (last_u2_element() - 1) :
   172                                     last_u2_element();
   173 }
   175 u2* ConstMethod::checked_exceptions_length_addr() const {
   176   // Located immediately before the generic signature index.
   177   assert(has_checked_exceptions(), "called only if table is present");
   178   if(has_method_parameters()) {
   179     // If method parameters present, locate immediately before them.
   180     return (u2*)method_parameters_start() - 1;
   181   } else {
   182     // Else, the exception table is at the end of the constMethod.
   183     return has_generic_signature() ? (last_u2_element() - 1) :
   184                                      last_u2_element();
   185   }
   186 }
   188 u2* ConstMethod::exception_table_length_addr() const {
   189   assert(has_exception_handler(), "called only if table is present");
   190   if (has_checked_exceptions()) {
   191     // If checked_exception present, locate immediately before them.
   192     return (u2*) checked_exceptions_start() - 1;
   193   } else {
   194     if(has_method_parameters()) {
   195       // If method parameters present, locate immediately before them.
   196       return (u2*)method_parameters_start() - 1;
   197     } else {
   198       // Else, the exception table is at the end of the constMethod.
   199       return has_generic_signature() ? (last_u2_element() - 1) :
   200                                         last_u2_element();
   201     }
   202   }
   203 }
   205 u2* ConstMethod::localvariable_table_length_addr() const {
   206   assert(has_localvariable_table(), "called only if table is present");
   207   if (has_exception_handler()) {
   208     // If exception_table present, locate immediately before them.
   209     return (u2*) exception_table_start() - 1;
   210   } else {
   211     if (has_checked_exceptions()) {
   212       // If checked_exception present, locate immediately before them.
   213       return (u2*) checked_exceptions_start() - 1;
   214     } else {
   215       if(has_method_parameters()) {
   216         // If method parameters present, locate immediately before them.
   217         return (u2*)method_parameters_start() - 1;
   218       } else {
   219         // Else, the exception table is at the end of the constMethod.
   220       return has_generic_signature() ? (last_u2_element() - 1) :
   221                                         last_u2_element();
   222       }
   223     }
   224   }
   225 }
   227 // Update the flags to indicate the presence of these optional fields.
   228 void ConstMethod::set_inlined_tables_length(InlineTableSizes* sizes) {
   229   _flags = 0;
   230   if (sizes->compressed_linenumber_size() > 0)
   231     _flags |= _has_linenumber_table;
   232   if (sizes->generic_signature_index() != 0)
   233     _flags |= _has_generic_signature;
   234   if (sizes->method_parameters_length() > 0)
   235     _flags |= _has_method_parameters;
   236   if (sizes->checked_exceptions_length() > 0)
   237     _flags |= _has_checked_exceptions;
   238   if (sizes->exception_table_length() > 0)
   239     _flags |= _has_exception_table;
   240   if (sizes->localvariable_table_length() > 0)
   241     _flags |= _has_localvariable_table;
   243   // annotations, they are all pointer sized embedded objects so don't have
   244   // a length embedded also.
   245   if (sizes->method_annotations_length() > 0)
   246     _flags |= _has_method_annotations;
   247   if (sizes->parameter_annotations_length() > 0)
   248     _flags |= _has_parameter_annotations;
   249   if (sizes->type_annotations_length() > 0)
   250     _flags |= _has_type_annotations;
   251   if (sizes->default_annotations_length() > 0)
   252     _flags |= _has_default_annotations;
   254   // This code is extremely brittle and should possibly be revised.
   255   // The *_length_addr functions walk backwards through the
   256   // constMethod data, using each of the length indexes ahead of them,
   257   // as well as the flags variable.  Therefore, the indexes must be
   258   // initialized in reverse order, or else they will compute the wrong
   259   // offsets.  Moving the initialization of _flags into a separate
   260   // block solves *half* of the problem, but the following part will
   261   // still break if the order is not exactly right.
   262   //
   263   // Also, the servicability agent needs to be informed anytime
   264   // anything is added here.  It might be advisable to have some sort
   265   // of indication of this inline.
   266   if (sizes->generic_signature_index() != 0)
   267     *(generic_signature_index_addr()) = sizes->generic_signature_index();
   268   // New data should probably go here.
   269   if (sizes->method_parameters_length() > 0)
   270     *(method_parameters_length_addr()) = sizes->method_parameters_length();
   271   if (sizes->checked_exceptions_length() > 0)
   272     *(checked_exceptions_length_addr()) = sizes->checked_exceptions_length();
   273   if (sizes->exception_table_length() > 0)
   274     *(exception_table_length_addr()) = sizes->exception_table_length();
   275   if (sizes->localvariable_table_length() > 0)
   276     *(localvariable_table_length_addr()) = sizes->localvariable_table_length();
   277 }
   279 int ConstMethod::method_parameters_length() const {
   280   return has_method_parameters() ? *(method_parameters_length_addr()) : 0;
   281 }
   283 MethodParametersElement* ConstMethod::method_parameters_start() const {
   284   u2* addr = method_parameters_length_addr();
   285   u2 length = *addr;
   286   assert(length > 0, "should only be called if table is present");
   287   addr -= length * sizeof(MethodParametersElement) / sizeof(u2);
   288   return (MethodParametersElement*) addr;
   289 }
   292 int ConstMethod::checked_exceptions_length() const {
   293   return has_checked_exceptions() ? *(checked_exceptions_length_addr()) : 0;
   294 }
   297 CheckedExceptionElement* ConstMethod::checked_exceptions_start() const {
   298   u2* addr = checked_exceptions_length_addr();
   299   u2 length = *addr;
   300   assert(length > 0, "should only be called if table is present");
   301   addr -= length * sizeof(CheckedExceptionElement) / sizeof(u2);
   302   return (CheckedExceptionElement*) addr;
   303 }
   306 int ConstMethod::localvariable_table_length() const {
   307   return has_localvariable_table() ? *(localvariable_table_length_addr()) : 0;
   308 }
   311 LocalVariableTableElement* ConstMethod::localvariable_table_start() const {
   312   u2* addr = localvariable_table_length_addr();
   313   u2 length = *addr;
   314   assert(length > 0, "should only be called if table is present");
   315   addr -= length * sizeof(LocalVariableTableElement) / sizeof(u2);
   316   return (LocalVariableTableElement*) addr;
   317 }
   319 int ConstMethod::exception_table_length() const {
   320   return has_exception_handler() ? *(exception_table_length_addr()) : 0;
   321 }
   323 ExceptionTableElement* ConstMethod::exception_table_start() const {
   324   u2* addr = exception_table_length_addr();
   325   u2 length = *addr;
   326   assert(length > 0, "should only be called if table is present");
   327   addr -= length * sizeof(ExceptionTableElement) / sizeof(u2);
   328   return (ExceptionTableElement*)addr;
   329 }
   331 AnnotationArray** ConstMethod::method_annotations_addr() const {
   332   assert(has_method_annotations(), "should only be called if method annotations are present");
   333   return (AnnotationArray**)constMethod_end() - 1;
   334 }
   336 AnnotationArray** ConstMethod::parameter_annotations_addr() const {
   337   assert(has_parameter_annotations(), "should only be called if method parameter annotations are present");
   338   int offset = 1;
   339   if (has_method_annotations()) offset++;
   340   return (AnnotationArray**)constMethod_end() - offset;
   341 }
   343 AnnotationArray** ConstMethod::type_annotations_addr() const {
   344   assert(has_type_annotations(), "should only be called if method type annotations are present");
   345   int offset = 1;
   346   if (has_method_annotations()) offset++;
   347   if (has_parameter_annotations()) offset++;
   348   return (AnnotationArray**)constMethod_end() - offset;
   349 }
   351 AnnotationArray** ConstMethod::default_annotations_addr() const {
   352   assert(has_default_annotations(), "should only be called if method default annotations are present");
   353   int offset = 1;
   354   if (has_method_annotations()) offset++;
   355   if (has_parameter_annotations()) offset++;
   356   if (has_type_annotations()) offset++;
   357   return (AnnotationArray**)constMethod_end() - offset;
   358 }
   360 // Printing
   362 void ConstMethod::print_on(outputStream* st) const {
   363   ResourceMark rm;
   364   assert(is_constMethod(), "must be constMethod");
   365   st->print_cr(internal_name());
   366   st->print(" - method:       " INTPTR_FORMAT " ", (address)method());
   367   method()->print_value_on(st); st->cr();
   368   if (has_stackmap_table()) {
   369     st->print(" - stackmap data:       ");
   370     stackmap_data()->print_value_on(st);
   371     st->cr();
   372   }
   373 }
   375 // Short version of printing ConstMethod* - just print the name of the
   376 // method it belongs to.
   377 void ConstMethod::print_value_on(outputStream* st) const {
   378   assert(is_constMethod(), "must be constMethod");
   379   st->print(" const part of method " );
   380   method()->print_value_on(st);
   381 }
   383 #if INCLUDE_SERVICES
   384 // Size Statistics
   385 void ConstMethod::collect_statistics(KlassSizeStats *sz) const {
   386   int n1, n2, n3;
   387   sz->_const_method_bytes += (n1 = sz->count(this));
   388   sz->_bytecode_bytes     += (n2 = code_size());
   389   sz->_stackmap_bytes     += (n3 = sz->count_array(stackmap_data()));
   391   // Count method annotations
   392   int a1 = 0, a2 = 0, a3 = 0, a4 = 0;
   393   if (has_method_annotations()) {
   394     sz->_methods_annotations_bytes += (a1 = sz->count_array(method_annotations()));
   395   }
   396   if (has_parameter_annotations()) {
   397     sz->_methods_parameter_annotations_bytes += (a2 = sz->count_array(parameter_annotations()));
   398   }
   399   if (has_type_annotations()) {
   400     sz->_methods_type_annotations_bytes += (a3 = sz->count_array(type_annotations()));
   401   }
   402   if (has_default_annotations()) {
   403     sz->_methods_default_annotations_bytes += (a4 = sz->count_array(default_annotations()));
   404   }
   406   int size_annotations = a1 + a2 + a3 + a4;
   408   sz->_method_all_bytes += n1 + n3 + size_annotations; // note: n2 is part of n3
   409   sz->_ro_bytes += n1 + n3 + size_annotations;
   410 }
   411 #endif // INCLUDE_SERVICES
   413 // Verification
   415 void ConstMethod::verify_on(outputStream* st) {
   416   guarantee(is_constMethod(), "object must be constMethod");
   417   guarantee(is_metadata(), err_msg("Should be metadata " PTR_FORMAT, this));
   419   // Verification can occur during oop construction before the method or
   420   // other fields have been initialized.
   421   guarantee(method()->is_method(), "should be method");
   423   address m_end = (address)((intptr_t) this + size());
   424   address compressed_table_start = code_end();
   425   guarantee(compressed_table_start <= m_end, "invalid method layout");
   426   address compressed_table_end = compressed_table_start;
   427   // Verify line number table
   428   if (has_linenumber_table()) {
   429     CompressedLineNumberReadStream stream(compressed_linenumber_table());
   430     while (stream.read_pair()) {
   431       guarantee(stream.bci() >= 0 && stream.bci() <= code_size(), "invalid bci in line number table");
   432     }
   433     compressed_table_end += stream.position();
   434   }
   435   guarantee(compressed_table_end <= m_end, "invalid method layout");
   436   // Verify checked exceptions, exception table and local variable tables
   437   if (has_method_parameters()) {
   438     u2* addr = method_parameters_length_addr();
   439     guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout");
   440   }
   441   if (has_checked_exceptions()) {
   442     u2* addr = checked_exceptions_length_addr();
   443     guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout");
   444   }
   445   if (has_exception_handler()) {
   446     u2* addr = exception_table_length_addr();
   447      guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout");
   448   }
   449   if (has_localvariable_table()) {
   450     u2* addr = localvariable_table_length_addr();
   451     guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout");
   452   }
   453   // Check compressed_table_end relative to uncompressed_table_start
   454   u2* uncompressed_table_start;
   455   if (has_localvariable_table()) {
   456     uncompressed_table_start = (u2*) localvariable_table_start();
   457   } else if (has_exception_handler()) {
   458     uncompressed_table_start = (u2*) exception_table_start();
   459   } else if (has_checked_exceptions()) {
   460       uncompressed_table_start = (u2*) checked_exceptions_start();
   461   } else if (has_method_parameters()) {
   462       uncompressed_table_start = (u2*) method_parameters_start();
   463   } else {
   464       uncompressed_table_start = (u2*) m_end;
   465   }
   466   int gap = (intptr_t) uncompressed_table_start - (intptr_t) compressed_table_end;
   467   int max_gap = align_object_size(1)*BytesPerWord;
   468   guarantee(gap >= 0 && gap < max_gap, "invalid method layout");
   469 }

mercurial