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

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

mercurial