annotate src/share/vm/oops/constMethodOop.cpp @ 3530:8150fa46d2ed

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