src/share/vm/oops/constMethodOop.cpp

Tue, 26 Jun 2012 19:08:44 -0400

author
jiangli
date
Tue, 26 Jun 2012 19:08:44 -0400
changeset 3917
8150fa46d2ed
parent 3826
2fe087c3e814
permissions
-rw-r--r--

7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
Summary: Change constMethodOop::_exception_table to optionally inlined u2 table.
Reviewed-by: bdelsart, coleenp, kamg

     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 "oops/constMethodOop.hpp"
    27 #include "oops/methodOop.hpp"
    29 // Static initialization
    30 const u2 constMethodOopDesc::MAX_IDNUM   = 0xFFFE;
    31 const u2 constMethodOopDesc::UNSET_IDNUM = 0xFFFF;
    33 // How big must this constMethodObject be?
    35 int constMethodOopDesc::object_size(int code_size,
    36                                     int compressed_line_number_size,
    37                                     int local_variable_table_length,
    38                                     int exception_table_length,
    39                                     int checked_exceptions_length) {
    40   int extra_bytes = code_size;
    41   if (compressed_line_number_size > 0) {
    42     extra_bytes += compressed_line_number_size;
    43   }
    44   if (checked_exceptions_length > 0) {
    45     extra_bytes += sizeof(u2);
    46     extra_bytes += checked_exceptions_length * sizeof(CheckedExceptionElement);
    47   }
    48   if (local_variable_table_length > 0) {
    49     extra_bytes += sizeof(u2);
    50     extra_bytes +=
    51               local_variable_table_length * sizeof(LocalVariableTableElement);
    52   }
    53   if (exception_table_length > 0) {
    54     extra_bytes += sizeof(u2);
    55     extra_bytes += exception_table_length * sizeof(ExceptionTableElement);
    56   }
    57   int extra_words = align_size_up(extra_bytes, BytesPerWord) / BytesPerWord;
    58   return align_object_size(header_size() + extra_words);
    59 }
    61 methodOop constMethodOopDesc::method() const {
    62     return instanceKlass::cast(_constants->pool_holder())->method_with_idnum(
    63                                _method_idnum);
    64   }
    66 // linenumber table - note that length is unknown until decompression,
    67 // see class CompressedLineNumberReadStream.
    69 u_char* constMethodOopDesc::compressed_linenumber_table() const {
    70   // Located immediately following the bytecodes.
    71   assert(has_linenumber_table(), "called only if table is present");
    72   return code_end();
    73 }
    75 u2* constMethodOopDesc::checked_exceptions_length_addr() const {
    76   // Located at the end of the constMethod.
    77   assert(has_checked_exceptions(), "called only if table is present");
    78   return last_u2_element();
    79 }
    81 u2* constMethodOopDesc::exception_table_length_addr() const {
    82   assert(has_exception_handler(), "called only if table is present");
    83   if (has_checked_exceptions()) {
    84     // If checked_exception present, locate immediately before them.
    85     return (u2*) checked_exceptions_start() - 1;
    86   } else {
    87     // Else, the exception table is at the end of the constMethod.
    88     return last_u2_element();
    89   }
    90 }
    92 u2* constMethodOopDesc::localvariable_table_length_addr() const {
    93   assert(has_localvariable_table(), "called only if table is present");
    94   if (has_exception_handler()) {
    95     // If exception_table present, locate immediately before them.
    96     return (u2*) exception_table_start() - 1;
    97   } else {
    98     if (has_checked_exceptions()) {
    99       // If checked_exception present, locate immediately before them.
   100       return (u2*) checked_exceptions_start() - 1;
   101     } else {
   102       // Else, the linenumber table is at the end of the constMethod.
   103       return last_u2_element();
   104     }
   105   }
   106 }
   109 // Update the flags to indicate the presence of these optional fields.
   110 void constMethodOopDesc::set_inlined_tables_length(
   111                                               int checked_exceptions_len,
   112                                               int compressed_line_number_size,
   113                                               int localvariable_table_len,
   114                                               int exception_table_len) {
   115   // Must be done in the order below, otherwise length_addr accessors
   116   // will not work. Only set bit in header if length is positive.
   117   assert(_flags == 0, "Error");
   118   if (compressed_line_number_size > 0) {
   119     _flags |= _has_linenumber_table;
   120   }
   121   if (checked_exceptions_len > 0) {
   122     _flags |= _has_checked_exceptions;
   123     *(checked_exceptions_length_addr()) = checked_exceptions_len;
   124   }
   125   if (exception_table_len > 0) {
   126     _flags |= _has_exception_table;
   127     *(exception_table_length_addr()) = exception_table_len;
   128   }
   129   if (localvariable_table_len > 0) {
   130     _flags |= _has_localvariable_table;
   131     *(localvariable_table_length_addr()) = localvariable_table_len;
   132   }
   133 }
   136 int constMethodOopDesc::checked_exceptions_length() const {
   137   return has_checked_exceptions() ? *(checked_exceptions_length_addr()) : 0;
   138 }
   141 CheckedExceptionElement* constMethodOopDesc::checked_exceptions_start() const {
   142   u2* addr = checked_exceptions_length_addr();
   143   u2 length = *addr;
   144   assert(length > 0, "should only be called if table is present");
   145   addr -= length * sizeof(CheckedExceptionElement) / sizeof(u2);
   146   return (CheckedExceptionElement*) addr;
   147 }
   150 int constMethodOopDesc::localvariable_table_length() const {
   151   return has_localvariable_table() ? *(localvariable_table_length_addr()) : 0;
   152 }
   155 LocalVariableTableElement* constMethodOopDesc::localvariable_table_start() const {
   156   u2* addr = localvariable_table_length_addr();
   157   u2 length = *addr;
   158   assert(length > 0, "should only be called if table is present");
   159   addr -= length * sizeof(LocalVariableTableElement) / sizeof(u2);
   160   return (LocalVariableTableElement*) addr;
   161 }
   163 int constMethodOopDesc::exception_table_length() const {
   164   return has_exception_handler() ? *(exception_table_length_addr()) : 0;
   165 }
   167 ExceptionTableElement* constMethodOopDesc::exception_table_start() const {
   168   u2* addr = exception_table_length_addr();
   169   u2 length = *addr;
   170   assert(length > 0, "should only be called if table is present");
   171   addr -= length * sizeof(ExceptionTableElement) / sizeof(u2);
   172   return (ExceptionTableElement*)addr;
   173 }

mercurial