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

duke@435 1 /*
jiangli@3826 2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "oops/constMethodOop.hpp"
stefank@2314 27 #include "oops/methodOop.hpp"
duke@435 28
duke@435 29 // Static initialization
duke@435 30 const u2 constMethodOopDesc::MAX_IDNUM = 0xFFFE;
duke@435 31 const u2 constMethodOopDesc::UNSET_IDNUM = 0xFFFF;
duke@435 32
duke@435 33 // How big must this constMethodObject be?
duke@435 34
duke@435 35 int constMethodOopDesc::object_size(int code_size,
duke@435 36 int compressed_line_number_size,
duke@435 37 int local_variable_table_length,
jiangli@3917 38 int exception_table_length,
duke@435 39 int checked_exceptions_length) {
duke@435 40 int extra_bytes = code_size;
duke@435 41 if (compressed_line_number_size > 0) {
duke@435 42 extra_bytes += compressed_line_number_size;
duke@435 43 }
duke@435 44 if (checked_exceptions_length > 0) {
duke@435 45 extra_bytes += sizeof(u2);
duke@435 46 extra_bytes += checked_exceptions_length * sizeof(CheckedExceptionElement);
duke@435 47 }
duke@435 48 if (local_variable_table_length > 0) {
duke@435 49 extra_bytes += sizeof(u2);
duke@435 50 extra_bytes +=
duke@435 51 local_variable_table_length * sizeof(LocalVariableTableElement);
duke@435 52 }
jiangli@3917 53 if (exception_table_length > 0) {
jiangli@3917 54 extra_bytes += sizeof(u2);
jiangli@3917 55 extra_bytes += exception_table_length * sizeof(ExceptionTableElement);
jiangli@3917 56 }
duke@435 57 int extra_words = align_size_up(extra_bytes, BytesPerWord) / BytesPerWord;
duke@435 58 return align_object_size(header_size() + extra_words);
duke@435 59 }
duke@435 60
jiangli@3826 61 methodOop constMethodOopDesc::method() const {
jiangli@3826 62 return instanceKlass::cast(_constants->pool_holder())->method_with_idnum(
jiangli@3826 63 _method_idnum);
jiangli@3826 64 }
duke@435 65
duke@435 66 // linenumber table - note that length is unknown until decompression,
duke@435 67 // see class CompressedLineNumberReadStream.
duke@435 68
duke@435 69 u_char* constMethodOopDesc::compressed_linenumber_table() const {
duke@435 70 // Located immediately following the bytecodes.
duke@435 71 assert(has_linenumber_table(), "called only if table is present");
duke@435 72 return code_end();
duke@435 73 }
duke@435 74
duke@435 75 u2* constMethodOopDesc::checked_exceptions_length_addr() const {
duke@435 76 // Located at the end of the constMethod.
duke@435 77 assert(has_checked_exceptions(), "called only if table is present");
duke@435 78 return last_u2_element();
duke@435 79 }
duke@435 80
jiangli@3917 81 u2* constMethodOopDesc::exception_table_length_addr() const {
jiangli@3917 82 assert(has_exception_handler(), "called only if table is present");
duke@435 83 if (has_checked_exceptions()) {
duke@435 84 // If checked_exception present, locate immediately before them.
duke@435 85 return (u2*) checked_exceptions_start() - 1;
duke@435 86 } else {
jiangli@3917 87 // Else, the exception table is at the end of the constMethod.
duke@435 88 return last_u2_element();
duke@435 89 }
duke@435 90 }
duke@435 91
jiangli@3917 92 u2* constMethodOopDesc::localvariable_table_length_addr() const {
jiangli@3917 93 assert(has_localvariable_table(), "called only if table is present");
jiangli@3917 94 if (has_exception_handler()) {
jiangli@3917 95 // If exception_table present, locate immediately before them.
jiangli@3917 96 return (u2*) exception_table_start() - 1;
jiangli@3917 97 } else {
jiangli@3917 98 if (has_checked_exceptions()) {
jiangli@3917 99 // If checked_exception present, locate immediately before them.
jiangli@3917 100 return (u2*) checked_exceptions_start() - 1;
jiangli@3917 101 } else {
jiangli@3917 102 // Else, the linenumber table is at the end of the constMethod.
jiangli@3917 103 return last_u2_element();
jiangli@3917 104 }
jiangli@3917 105 }
jiangli@3917 106 }
jiangli@3917 107
duke@435 108
duke@435 109 // Update the flags to indicate the presence of these optional fields.
duke@435 110 void constMethodOopDesc::set_inlined_tables_length(
duke@435 111 int checked_exceptions_len,
duke@435 112 int compressed_line_number_size,
jiangli@3917 113 int localvariable_table_len,
jiangli@3917 114 int exception_table_len) {
duke@435 115 // Must be done in the order below, otherwise length_addr accessors
duke@435 116 // will not work. Only set bit in header if length is positive.
duke@435 117 assert(_flags == 0, "Error");
duke@435 118 if (compressed_line_number_size > 0) {
duke@435 119 _flags |= _has_linenumber_table;
duke@435 120 }
duke@435 121 if (checked_exceptions_len > 0) {
duke@435 122 _flags |= _has_checked_exceptions;
duke@435 123 *(checked_exceptions_length_addr()) = checked_exceptions_len;
duke@435 124 }
jiangli@3917 125 if (exception_table_len > 0) {
jiangli@3917 126 _flags |= _has_exception_table;
jiangli@3917 127 *(exception_table_length_addr()) = exception_table_len;
jiangli@3917 128 }
duke@435 129 if (localvariable_table_len > 0) {
duke@435 130 _flags |= _has_localvariable_table;
duke@435 131 *(localvariable_table_length_addr()) = localvariable_table_len;
duke@435 132 }
duke@435 133 }
duke@435 134
duke@435 135
duke@435 136 int constMethodOopDesc::checked_exceptions_length() const {
duke@435 137 return has_checked_exceptions() ? *(checked_exceptions_length_addr()) : 0;
duke@435 138 }
duke@435 139
duke@435 140
duke@435 141 CheckedExceptionElement* constMethodOopDesc::checked_exceptions_start() const {
duke@435 142 u2* addr = checked_exceptions_length_addr();
duke@435 143 u2 length = *addr;
duke@435 144 assert(length > 0, "should only be called if table is present");
duke@435 145 addr -= length * sizeof(CheckedExceptionElement) / sizeof(u2);
duke@435 146 return (CheckedExceptionElement*) addr;
duke@435 147 }
duke@435 148
duke@435 149
duke@435 150 int constMethodOopDesc::localvariable_table_length() const {
duke@435 151 return has_localvariable_table() ? *(localvariable_table_length_addr()) : 0;
duke@435 152 }
duke@435 153
duke@435 154
duke@435 155 LocalVariableTableElement* constMethodOopDesc::localvariable_table_start() const {
duke@435 156 u2* addr = localvariable_table_length_addr();
duke@435 157 u2 length = *addr;
duke@435 158 assert(length > 0, "should only be called if table is present");
duke@435 159 addr -= length * sizeof(LocalVariableTableElement) / sizeof(u2);
duke@435 160 return (LocalVariableTableElement*) addr;
duke@435 161 }
jiangli@3917 162
jiangli@3917 163 int constMethodOopDesc::exception_table_length() const {
jiangli@3917 164 return has_exception_handler() ? *(exception_table_length_addr()) : 0;
jiangli@3917 165 }
jiangli@3917 166
jiangli@3917 167 ExceptionTableElement* constMethodOopDesc::exception_table_start() const {
jiangli@3917 168 u2* addr = exception_table_length_addr();
jiangli@3917 169 u2 length = *addr;
jiangli@3917 170 assert(length > 0, "should only be called if table is present");
jiangli@3917 171 addr -= length * sizeof(ExceptionTableElement) / sizeof(u2);
jiangli@3917 172 return (ExceptionTableElement*)addr;
jiangli@3917 173 }

mercurial