src/share/vm/oops/constMethod.cpp

Wed, 02 Jan 2013 20:28:09 -0500

author
coleenp
date
Wed, 02 Jan 2013 20:28:09 -0500
changeset 4395
cc6a617fffd2
parent 4302
b2dbd323c668
child 4398
ade95d680b42
permissions
-rw-r--r--

8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
Summary: Relocate functions with jsr's when rewriting so not repeated after reading shared archive
Reviewed-by: twisti, jrose

     1 /*
     2  * Copyright (c) 2003, 2012, 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/metadataFactory.hpp"
    29 #include "oops/constMethod.hpp"
    30 #include "oops/method.hpp"
    32 // Static initialization
    33 const u2 ConstMethod::MAX_IDNUM   = 0xFFFE;
    34 const u2 ConstMethod::UNSET_IDNUM = 0xFFFF;
    36 ConstMethod* ConstMethod::allocate(ClassLoaderData* loader_data,
    37                                    int byte_code_size,
    38                                    int compressed_line_number_size,
    39                                    int localvariable_table_length,
    40                                    int exception_table_length,
    41                                    int checked_exceptions_length,
    42                                    u2  generic_signature_index,
    43                                    MethodType method_type,
    44                                    TRAPS) {
    45   int size = ConstMethod::size(byte_code_size,
    46                                       compressed_line_number_size,
    47                                       localvariable_table_length,
    48                                       exception_table_length,
    49                                       checked_exceptions_length,
    50                                       generic_signature_index);
    51   return new (loader_data, size, true, THREAD) ConstMethod(
    52       byte_code_size, compressed_line_number_size, localvariable_table_length,
    53       exception_table_length, checked_exceptions_length, generic_signature_index,
    54       method_type, size);
    55 }
    57 ConstMethod::ConstMethod(int byte_code_size,
    58                          int compressed_line_number_size,
    59                          int localvariable_table_length,
    60                          int exception_table_length,
    61                          int checked_exceptions_length,
    62                          u2  generic_signature_index,
    63                          MethodType method_type,
    64                          int size) {
    66   No_Safepoint_Verifier no_safepoint;
    67   set_interpreter_kind(Interpreter::invalid);
    68   init_fingerprint();
    69   set_constants(NULL);
    70   set_stackmap_data(NULL);
    71   set_code_size(byte_code_size);
    72   set_constMethod_size(size);
    73   set_inlined_tables_length(generic_signature_index,
    74                             checked_exceptions_length,
    75                             compressed_line_number_size,
    76                             localvariable_table_length,
    77                             exception_table_length);
    78   set_method_type(method_type);
    79   assert(this->size() == size, "wrong size for object");
    80 }
    83 // Deallocate metadata fields associated with ConstMethod*
    84 void ConstMethod::deallocate_contents(ClassLoaderData* loader_data) {
    85   set_interpreter_kind(Interpreter::invalid);
    86   if (stackmap_data() != NULL) {
    87     MetadataFactory::free_array<u1>(loader_data, stackmap_data());
    88   }
    89   set_stackmap_data(NULL);
    90 }
    92 // How big must this constMethodObject be?
    94 int ConstMethod::size(int code_size,
    95                                     int compressed_line_number_size,
    96                                     int local_variable_table_length,
    97                                     int exception_table_length,
    98                                     int checked_exceptions_length,
    99                                     u2  generic_signature_index) {
   100   int extra_bytes = code_size;
   101   if (compressed_line_number_size > 0) {
   102     extra_bytes += compressed_line_number_size;
   103   }
   104   if (checked_exceptions_length > 0) {
   105     extra_bytes += sizeof(u2);
   106     extra_bytes += checked_exceptions_length * sizeof(CheckedExceptionElement);
   107   }
   108   if (local_variable_table_length > 0) {
   109     extra_bytes += sizeof(u2);
   110     extra_bytes +=
   111               local_variable_table_length * sizeof(LocalVariableTableElement);
   112   }
   113   if (exception_table_length > 0) {
   114     extra_bytes += sizeof(u2);
   115     extra_bytes += exception_table_length * sizeof(ExceptionTableElement);
   116   }
   117   if (generic_signature_index != 0) {
   118     extra_bytes += sizeof(u2);
   119   }
   120   int extra_words = align_size_up(extra_bytes, BytesPerWord) / BytesPerWord;
   121   return align_object_size(header_size() + extra_words);
   122 }
   124 Method* ConstMethod::method() const {
   125     return _constants->pool_holder()->method_with_idnum(_method_idnum);
   126   }
   128 // linenumber table - note that length is unknown until decompression,
   129 // see class CompressedLineNumberReadStream.
   131 u_char* ConstMethod::compressed_linenumber_table() const {
   132   // Located immediately following the bytecodes.
   133   assert(has_linenumber_table(), "called only if table is present");
   134   return code_end();
   135 }
   137 u2* ConstMethod::generic_signature_index_addr() const {
   138   // Located at the end of the constMethod.
   139   assert(has_generic_signature(), "called only if generic signature exists");
   140   return last_u2_element();
   141 }
   143 u2* ConstMethod::checked_exceptions_length_addr() const {
   144   // Located immediately before the generic signature index.
   145   assert(has_checked_exceptions(), "called only if table is present");
   146   return has_generic_signature() ? (last_u2_element() - 1) :
   147                                     last_u2_element();
   148 }
   150 u2* ConstMethod::exception_table_length_addr() const {
   151   assert(has_exception_handler(), "called only if table is present");
   152   if (has_checked_exceptions()) {
   153     // If checked_exception present, locate immediately before them.
   154     return (u2*) checked_exceptions_start() - 1;
   155   } else {
   156     // Else, the exception table is at the end of the constMethod or
   157     // immediately before the generic signature index.
   158     return has_generic_signature() ? (last_u2_element() - 1) :
   159                                       last_u2_element();
   160   }
   161 }
   163 u2* ConstMethod::localvariable_table_length_addr() const {
   164   assert(has_localvariable_table(), "called only if table is present");
   165   if (has_exception_handler()) {
   166     // If exception_table present, locate immediately before them.
   167     return (u2*) exception_table_start() - 1;
   168   } else {
   169     if (has_checked_exceptions()) {
   170       // If checked_exception present, locate immediately before them.
   171       return (u2*) checked_exceptions_start() - 1;
   172     } else {
   173       // Else, the linenumber table is at the end of the constMethod or
   174       // immediately before the generic signature index.
   175       return has_generic_signature() ? (last_u2_element() - 1) :
   176                                         last_u2_element();
   177     }
   178   }
   179 }
   181 // Update the flags to indicate the presence of these optional fields.
   182 void ConstMethod::set_inlined_tables_length(u2  generic_signature_index,
   183                                             int checked_exceptions_len,
   184                                             int compressed_line_number_size,
   185                                             int localvariable_table_len,
   186                                             int exception_table_len) {
   187   // Must be done in the order below, otherwise length_addr accessors
   188   // will not work. Only set bit in header if length is positive.
   189   assert(_flags == 0, "Error");
   190   if (compressed_line_number_size > 0) {
   191     _flags |= _has_linenumber_table;
   192   }
   193   if (generic_signature_index != 0) {
   194     _flags |= _has_generic_signature;
   195     *(generic_signature_index_addr()) = generic_signature_index;
   196   }
   197   if (checked_exceptions_len > 0) {
   198     _flags |= _has_checked_exceptions;
   199     *(checked_exceptions_length_addr()) = checked_exceptions_len;
   200   }
   201   if (exception_table_len > 0) {
   202     _flags |= _has_exception_table;
   203     *(exception_table_length_addr()) = exception_table_len;
   204   }
   205   if (localvariable_table_len > 0) {
   206     _flags |= _has_localvariable_table;
   207     *(localvariable_table_length_addr()) = localvariable_table_len;
   208   }
   209 }
   212 int ConstMethod::checked_exceptions_length() const {
   213   return has_checked_exceptions() ? *(checked_exceptions_length_addr()) : 0;
   214 }
   217 CheckedExceptionElement* ConstMethod::checked_exceptions_start() const {
   218   u2* addr = checked_exceptions_length_addr();
   219   u2 length = *addr;
   220   assert(length > 0, "should only be called if table is present");
   221   addr -= length * sizeof(CheckedExceptionElement) / sizeof(u2);
   222   return (CheckedExceptionElement*) addr;
   223 }
   226 int ConstMethod::localvariable_table_length() const {
   227   return has_localvariable_table() ? *(localvariable_table_length_addr()) : 0;
   228 }
   231 LocalVariableTableElement* ConstMethod::localvariable_table_start() const {
   232   u2* addr = localvariable_table_length_addr();
   233   u2 length = *addr;
   234   assert(length > 0, "should only be called if table is present");
   235   addr -= length * sizeof(LocalVariableTableElement) / sizeof(u2);
   236   return (LocalVariableTableElement*) addr;
   237 }
   239 int ConstMethod::exception_table_length() const {
   240   return has_exception_handler() ? *(exception_table_length_addr()) : 0;
   241 }
   243 ExceptionTableElement* ConstMethod::exception_table_start() const {
   244   u2* addr = exception_table_length_addr();
   245   u2 length = *addr;
   246   assert(length > 0, "should only be called if table is present");
   247   addr -= length * sizeof(ExceptionTableElement) / sizeof(u2);
   248   return (ExceptionTableElement*)addr;
   249 }
   252 // Printing
   254 void ConstMethod::print_on(outputStream* st) const {
   255   ResourceMark rm;
   256   assert(is_constMethod(), "must be constMethod");
   257   st->print_cr(internal_name());
   258   st->print(" - method:       " INTPTR_FORMAT " ", (address)method());
   259   method()->print_value_on(st); st->cr();
   260   if (has_stackmap_table()) {
   261     st->print(" - stackmap data:       ");
   262     stackmap_data()->print_value_on(st);
   263     st->cr();
   264   }
   265 }
   267 // Short version of printing ConstMethod* - just print the name of the
   268 // method it belongs to.
   269 void ConstMethod::print_value_on(outputStream* st) const {
   270   assert(is_constMethod(), "must be constMethod");
   271   st->print(" const part of method " );
   272   method()->print_value_on(st);
   273 }
   276 // Verification
   278 void ConstMethod::verify_on(outputStream* st) {
   279   guarantee(is_constMethod(), "object must be constMethod");
   280   guarantee(is_metadata(), err_msg("Should be metadata " PTR_FORMAT, this));
   282   // Verification can occur during oop construction before the method or
   283   // other fields have been initialized.
   284   guarantee(is_metadata(), err_msg("Should be metadata " PTR_FORMAT, this));
   285   guarantee(method()->is_method(), "should be method");
   287   address m_end = (address)((oop*) this + size());
   288   address compressed_table_start = code_end();
   289   guarantee(compressed_table_start <= m_end, "invalid method layout");
   290   address compressed_table_end = compressed_table_start;
   291   // Verify line number table
   292   if (has_linenumber_table()) {
   293     CompressedLineNumberReadStream stream(compressed_linenumber_table());
   294     while (stream.read_pair()) {
   295       guarantee(stream.bci() >= 0 && stream.bci() <= code_size(), "invalid bci in line number table");
   296     }
   297     compressed_table_end += stream.position();
   298   }
   299   guarantee(compressed_table_end <= m_end, "invalid method layout");
   300   // Verify checked exceptions, exception table and local variable tables
   301   if (has_checked_exceptions()) {
   302     u2* addr = checked_exceptions_length_addr();
   303     guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout");
   304   }
   305   if (has_exception_handler()) {
   306     u2* addr = exception_table_length_addr();
   307      guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout");
   308   }
   309   if (has_localvariable_table()) {
   310     u2* addr = localvariable_table_length_addr();
   311     guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout");
   312   }
   313   // Check compressed_table_end relative to uncompressed_table_start
   314   u2* uncompressed_table_start;
   315   if (has_localvariable_table()) {
   316     uncompressed_table_start = (u2*) localvariable_table_start();
   317   } else if (has_exception_handler()) {
   318     uncompressed_table_start = (u2*) exception_table_start();
   319   } else if (has_checked_exceptions()) {
   320       uncompressed_table_start = (u2*) checked_exceptions_start();
   321   } else {
   322       uncompressed_table_start = (u2*) m_end;
   323   }
   324   int gap = (intptr_t) uncompressed_table_start - (intptr_t) compressed_table_end;
   325   int max_gap = align_object_size(1)*BytesPerWord;
   326   guarantee(gap >= 0 && gap < max_gap, "invalid method layout");
   327 }

mercurial