src/share/vm/oops/constMethod.cpp

Wed, 13 Mar 2013 09:10:35 -0400

author
coleenp
date
Wed, 13 Mar 2013 09:10:35 -0400
changeset 4715
5939f5953b45
parent 4712
3efdfd6ddbf2
child 4719
c8b31b461e1a
permissions
-rw-r--r--

8009836: nsk/regression/b4222717 fails with empty stack trace
Summary: Some zeroing was missed for bug 8003553, causing empty stack traces and Xcom crashes, add back zeroing to metablock
Reviewed-by: dholmes, rbackman

duke@435 1 /*
acorn@4497 2 * Copyright (c) 2003, 2013, 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"
acorn@4497 28 #include "memory/heapInspection.hpp"
coleenp@4037 29 #include "memory/metadataFactory.hpp"
coleenp@4037 30 #include "oops/constMethod.hpp"
coleenp@4037 31 #include "oops/method.hpp"
duke@435 32
duke@435 33 // Static initialization
coleenp@4037 34 const u2 ConstMethod::MAX_IDNUM = 0xFFFE;
coleenp@4037 35 const u2 ConstMethod::UNSET_IDNUM = 0xFFFF;
coleenp@4037 36
coleenp@4037 37 ConstMethod* ConstMethod::allocate(ClassLoaderData* loader_data,
kamg@4245 38 int byte_code_size,
coleenp@4572 39 InlineTableSizes* sizes,
kamg@4245 40 MethodType method_type,
kamg@4245 41 TRAPS) {
coleenp@4572 42 int size = ConstMethod::size(byte_code_size, sizes);
coleenp@4037 43 return new (loader_data, size, true, THREAD) ConstMethod(
coleenp@4572 44 byte_code_size, sizes, method_type, size);
coleenp@4037 45 }
coleenp@4037 46
coleenp@4037 47 ConstMethod::ConstMethod(int byte_code_size,
coleenp@4572 48 InlineTableSizes* sizes,
kamg@4245 49 MethodType method_type,
kamg@4245 50 int size) {
coleenp@4037 51
coleenp@4037 52 No_Safepoint_Verifier no_safepoint;
coleenp@4037 53 init_fingerprint();
coleenp@4037 54 set_constants(NULL);
coleenp@4037 55 set_stackmap_data(NULL);
coleenp@4037 56 set_code_size(byte_code_size);
coleenp@4037 57 set_constMethod_size(size);
coleenp@4715 58 set_inlined_tables_length(sizes); // sets _flags
kamg@4245 59 set_method_type(method_type);
coleenp@4037 60 assert(this->size() == size, "wrong size for object");
coleenp@4712 61 set_name_index(0);
coleenp@4712 62 set_signature_index(0);
coleenp@4712 63 set_constants(NULL);
coleenp@4712 64 set_max_stack(0);
coleenp@4712 65 set_max_locals(0);
coleenp@4712 66 set_method_idnum(0);
coleenp@4715 67 set_size_of_parameters(0);
coleenp@4037 68 }
coleenp@4037 69
coleenp@4037 70
coleenp@4037 71 // Deallocate metadata fields associated with ConstMethod*
coleenp@4037 72 void ConstMethod::deallocate_contents(ClassLoaderData* loader_data) {
coleenp@4037 73 if (stackmap_data() != NULL) {
coleenp@4037 74 MetadataFactory::free_array<u1>(loader_data, stackmap_data());
coleenp@4037 75 }
coleenp@4037 76 set_stackmap_data(NULL);
coleenp@4572 77
coleenp@4572 78 // deallocate annotation arrays
coleenp@4572 79 if (has_method_annotations())
coleenp@4572 80 MetadataFactory::free_array<u1>(loader_data, method_annotations());
coleenp@4572 81 if (has_parameter_annotations())
coleenp@4572 82 MetadataFactory::free_array<u1>(loader_data, parameter_annotations());
coleenp@4572 83 if (has_type_annotations())
coleenp@4572 84 MetadataFactory::free_array<u1>(loader_data, type_annotations());
coleenp@4572 85 if (has_default_annotations())
coleenp@4572 86 MetadataFactory::free_array<u1>(loader_data, default_annotations());
coleenp@4037 87 }
duke@435 88
duke@435 89 // How big must this constMethodObject be?
duke@435 90
coleenp@4037 91 int ConstMethod::size(int code_size,
coleenp@4572 92 InlineTableSizes* sizes) {
duke@435 93 int extra_bytes = code_size;
coleenp@4572 94 if (sizes->compressed_linenumber_size() > 0) {
coleenp@4572 95 extra_bytes += sizes->compressed_linenumber_size();
duke@435 96 }
coleenp@4572 97 if (sizes->checked_exceptions_length() > 0) {
duke@435 98 extra_bytes += sizeof(u2);
coleenp@4572 99 extra_bytes += sizes->checked_exceptions_length() * sizeof(CheckedExceptionElement);
duke@435 100 }
coleenp@4572 101 if (sizes->localvariable_table_length() > 0) {
duke@435 102 extra_bytes += sizeof(u2);
duke@435 103 extra_bytes +=
coleenp@4572 104 sizes->localvariable_table_length() * sizeof(LocalVariableTableElement);
duke@435 105 }
coleenp@4572 106 if (sizes->exception_table_length() > 0) {
jiangli@3917 107 extra_bytes += sizeof(u2);
coleenp@4572 108 extra_bytes += sizes->exception_table_length() * sizeof(ExceptionTableElement);
jiangli@3917 109 }
coleenp@4572 110 if (sizes->generic_signature_index() != 0) {
jiangli@4302 111 extra_bytes += sizeof(u2);
jiangli@4302 112 }
coleenp@4572 113 if (sizes->method_parameters_length() > 0) {
coleenp@4398 114 extra_bytes += sizeof(u2);
coleenp@4572 115 extra_bytes += sizes->method_parameters_length() * sizeof(MethodParametersElement);
coleenp@4398 116 }
coleenp@4572 117
coleenp@4572 118 // Align sizes up to a word.
coleenp@4572 119 extra_bytes = align_size_up(extra_bytes, BytesPerWord);
coleenp@4572 120
coleenp@4572 121 // One pointer per annotation array
coleenp@4572 122 if (sizes->method_annotations_length() > 0) {
coleenp@4572 123 extra_bytes += sizeof(AnnotationArray*);
coleenp@4572 124 }
coleenp@4572 125 if (sizes->parameter_annotations_length() > 0) {
coleenp@4572 126 extra_bytes += sizeof(AnnotationArray*);
coleenp@4572 127 }
coleenp@4572 128 if (sizes->type_annotations_length() > 0) {
coleenp@4572 129 extra_bytes += sizeof(AnnotationArray*);
coleenp@4572 130 }
coleenp@4572 131 if (sizes->default_annotations_length() > 0) {
coleenp@4572 132 extra_bytes += sizeof(AnnotationArray*);
coleenp@4572 133 }
coleenp@4572 134
duke@435 135 int extra_words = align_size_up(extra_bytes, BytesPerWord) / BytesPerWord;
coleenp@4572 136 assert(extra_words == extra_bytes/BytesPerWord, "should already be aligned");
duke@435 137 return align_object_size(header_size() + extra_words);
duke@435 138 }
duke@435 139
coleenp@4037 140 Method* ConstMethod::method() const {
coleenp@4251 141 return _constants->pool_holder()->method_with_idnum(_method_idnum);
jiangli@3826 142 }
duke@435 143
duke@435 144 // linenumber table - note that length is unknown until decompression,
duke@435 145 // see class CompressedLineNumberReadStream.
duke@435 146
coleenp@4037 147 u_char* ConstMethod::compressed_linenumber_table() const {
duke@435 148 // Located immediately following the bytecodes.
duke@435 149 assert(has_linenumber_table(), "called only if table is present");
duke@435 150 return code_end();
duke@435 151 }
duke@435 152
coleenp@4572 153 // Last short in ConstMethod* before annotations
coleenp@4572 154 u2* ConstMethod::last_u2_element() const {
coleenp@4572 155 int offset = 0;
coleenp@4572 156 if (has_method_annotations()) offset++;
coleenp@4572 157 if (has_parameter_annotations()) offset++;
coleenp@4572 158 if (has_type_annotations()) offset++;
coleenp@4572 159 if (has_default_annotations()) offset++;
coleenp@4572 160 return (u2*)((AnnotationArray**)constMethod_end() - offset) - 1;
coleenp@4572 161 }
coleenp@4572 162
jiangli@4302 163 u2* ConstMethod::generic_signature_index_addr() const {
jiangli@4302 164 // Located at the end of the constMethod.
jiangli@4302 165 assert(has_generic_signature(), "called only if generic signature exists");
jiangli@4302 166 return last_u2_element();
jiangli@4302 167 }
jiangli@4302 168
coleenp@4572 169 u2* ConstMethod::method_parameters_length_addr() const {
coleenp@4572 170 assert(has_method_parameters(), "called only if table is present");
coleenp@4572 171 return has_generic_signature() ? (last_u2_element() - 1) :
coleenp@4572 172 last_u2_element();
coleenp@4572 173 }
coleenp@4572 174
coleenp@4037 175 u2* ConstMethod::checked_exceptions_length_addr() const {
jiangli@4302 176 // Located immediately before the generic signature index.
duke@435 177 assert(has_checked_exceptions(), "called only if table is present");
coleenp@4398 178 if(has_method_parameters()) {
coleenp@4398 179 // If method parameters present, locate immediately before them.
coleenp@4398 180 return (u2*)method_parameters_start() - 1;
coleenp@4398 181 } else {
coleenp@4398 182 // Else, the exception table is at the end of the constMethod.
coleenp@4398 183 return has_generic_signature() ? (last_u2_element() - 1) :
coleenp@4398 184 last_u2_element();
coleenp@4398 185 }
coleenp@4398 186 }
coleenp@4398 187
coleenp@4037 188 u2* ConstMethod::exception_table_length_addr() const {
jiangli@3917 189 assert(has_exception_handler(), "called only if table is present");
duke@435 190 if (has_checked_exceptions()) {
duke@435 191 // If checked_exception present, locate immediately before them.
duke@435 192 return (u2*) checked_exceptions_start() - 1;
duke@435 193 } else {
coleenp@4398 194 if(has_method_parameters()) {
coleenp@4398 195 // If method parameters present, locate immediately before them.
coleenp@4398 196 return (u2*)method_parameters_start() - 1;
coleenp@4398 197 } else {
coleenp@4398 198 // Else, the exception table is at the end of the constMethod.
coleenp@4572 199 return has_generic_signature() ? (last_u2_element() - 1) :
coleenp@4572 200 last_u2_element();
coleenp@4572 201 }
coleenp@4398 202 }
duke@435 203 }
duke@435 204
coleenp@4037 205 u2* ConstMethod::localvariable_table_length_addr() const {
jiangli@3917 206 assert(has_localvariable_table(), "called only if table is present");
jiangli@3917 207 if (has_exception_handler()) {
jiangli@3917 208 // If exception_table present, locate immediately before them.
jiangli@3917 209 return (u2*) exception_table_start() - 1;
jiangli@3917 210 } else {
jiangli@3917 211 if (has_checked_exceptions()) {
jiangli@3917 212 // If checked_exception present, locate immediately before them.
jiangli@3917 213 return (u2*) checked_exceptions_start() - 1;
jiangli@3917 214 } else {
coleenp@4398 215 if(has_method_parameters()) {
coleenp@4398 216 // If method parameters present, locate immediately before them.
coleenp@4398 217 return (u2*)method_parameters_start() - 1;
coleenp@4398 218 } else {
coleenp@4398 219 // Else, the exception table is at the end of the constMethod.
jiangli@4302 220 return has_generic_signature() ? (last_u2_element() - 1) :
jiangli@4302 221 last_u2_element();
coleenp@4572 222 }
jiangli@3917 223 }
jiangli@3917 224 }
jiangli@3917 225 }
jiangli@3917 226
duke@435 227 // Update the flags to indicate the presence of these optional fields.
coleenp@4572 228 void ConstMethod::set_inlined_tables_length(InlineTableSizes* sizes) {
coleenp@4572 229 _flags = 0;
coleenp@4572 230 if (sizes->compressed_linenumber_size() > 0)
duke@435 231 _flags |= _has_linenumber_table;
coleenp@4572 232 if (sizes->generic_signature_index() != 0)
jiangli@4302 233 _flags |= _has_generic_signature;
coleenp@4572 234 if (sizes->method_parameters_length() > 0)
coleenp@4398 235 _flags |= _has_method_parameters;
coleenp@4572 236 if (sizes->checked_exceptions_length() > 0)
coleenp@4398 237 _flags |= _has_checked_exceptions;
coleenp@4572 238 if (sizes->exception_table_length() > 0)
coleenp@4398 239 _flags |= _has_exception_table;
coleenp@4572 240 if (sizes->localvariable_table_length() > 0)
coleenp@4398 241 _flags |= _has_localvariable_table;
coleenp@4398 242
coleenp@4572 243 // annotations, they are all pointer sized embedded objects so don't have
coleenp@4572 244 // a length embedded also.
coleenp@4572 245 if (sizes->method_annotations_length() > 0)
coleenp@4572 246 _flags |= _has_method_annotations;
coleenp@4572 247 if (sizes->parameter_annotations_length() > 0)
coleenp@4572 248 _flags |= _has_parameter_annotations;
coleenp@4572 249 if (sizes->type_annotations_length() > 0)
coleenp@4572 250 _flags |= _has_type_annotations;
coleenp@4572 251 if (sizes->default_annotations_length() > 0)
coleenp@4572 252 _flags |= _has_default_annotations;
coleenp@4572 253
coleenp@4398 254 // This code is extremely brittle and should possibly be revised.
coleenp@4398 255 // The *_length_addr functions walk backwards through the
coleenp@4398 256 // constMethod data, using each of the length indexes ahead of them,
coleenp@4398 257 // as well as the flags variable. Therefore, the indexes must be
coleenp@4398 258 // initialized in reverse order, or else they will compute the wrong
coleenp@4398 259 // offsets. Moving the initialization of _flags into a separate
coleenp@4398 260 // block solves *half* of the problem, but the following part will
coleenp@4398 261 // still break if the order is not exactly right.
coleenp@4398 262 //
coleenp@4398 263 // Also, the servicability agent needs to be informed anytime
coleenp@4398 264 // anything is added here. It might be advisable to have some sort
coleenp@4398 265 // of indication of this inline.
coleenp@4572 266 if (sizes->generic_signature_index() != 0)
coleenp@4572 267 *(generic_signature_index_addr()) = sizes->generic_signature_index();
coleenp@4398 268 // New data should probably go here.
coleenp@4572 269 if (sizes->method_parameters_length() > 0)
coleenp@4572 270 *(method_parameters_length_addr()) = sizes->method_parameters_length();
coleenp@4572 271 if (sizes->checked_exceptions_length() > 0)
coleenp@4572 272 *(checked_exceptions_length_addr()) = sizes->checked_exceptions_length();
coleenp@4572 273 if (sizes->exception_table_length() > 0)
coleenp@4572 274 *(exception_table_length_addr()) = sizes->exception_table_length();
coleenp@4572 275 if (sizes->localvariable_table_length() > 0)
coleenp@4572 276 *(localvariable_table_length_addr()) = sizes->localvariable_table_length();
coleenp@4398 277 }
coleenp@4398 278
coleenp@4398 279 int ConstMethod::method_parameters_length() const {
coleenp@4398 280 return has_method_parameters() ? *(method_parameters_length_addr()) : 0;
coleenp@4398 281 }
coleenp@4398 282
coleenp@4398 283 MethodParametersElement* ConstMethod::method_parameters_start() const {
coleenp@4398 284 u2* addr = method_parameters_length_addr();
coleenp@4398 285 u2 length = *addr;
coleenp@4398 286 assert(length > 0, "should only be called if table is present");
coleenp@4398 287 addr -= length * sizeof(MethodParametersElement) / sizeof(u2);
coleenp@4398 288 return (MethodParametersElement*) addr;
duke@435 289 }
duke@435 290
duke@435 291
coleenp@4037 292 int ConstMethod::checked_exceptions_length() const {
duke@435 293 return has_checked_exceptions() ? *(checked_exceptions_length_addr()) : 0;
duke@435 294 }
duke@435 295
duke@435 296
coleenp@4037 297 CheckedExceptionElement* ConstMethod::checked_exceptions_start() const {
duke@435 298 u2* addr = checked_exceptions_length_addr();
duke@435 299 u2 length = *addr;
duke@435 300 assert(length > 0, "should only be called if table is present");
duke@435 301 addr -= length * sizeof(CheckedExceptionElement) / sizeof(u2);
duke@435 302 return (CheckedExceptionElement*) addr;
duke@435 303 }
duke@435 304
duke@435 305
coleenp@4037 306 int ConstMethod::localvariable_table_length() const {
duke@435 307 return has_localvariable_table() ? *(localvariable_table_length_addr()) : 0;
duke@435 308 }
duke@435 309
duke@435 310
coleenp@4037 311 LocalVariableTableElement* ConstMethod::localvariable_table_start() const {
duke@435 312 u2* addr = localvariable_table_length_addr();
duke@435 313 u2 length = *addr;
duke@435 314 assert(length > 0, "should only be called if table is present");
duke@435 315 addr -= length * sizeof(LocalVariableTableElement) / sizeof(u2);
duke@435 316 return (LocalVariableTableElement*) addr;
duke@435 317 }
jiangli@3917 318
coleenp@4037 319 int ConstMethod::exception_table_length() const {
jiangli@3917 320 return has_exception_handler() ? *(exception_table_length_addr()) : 0;
jiangli@3917 321 }
jiangli@3917 322
coleenp@4037 323 ExceptionTableElement* ConstMethod::exception_table_start() const {
jiangli@3917 324 u2* addr = exception_table_length_addr();
jiangli@3917 325 u2 length = *addr;
jiangli@3917 326 assert(length > 0, "should only be called if table is present");
jiangli@3917 327 addr -= length * sizeof(ExceptionTableElement) / sizeof(u2);
jiangli@3917 328 return (ExceptionTableElement*)addr;
jiangli@3917 329 }
coleenp@4037 330
coleenp@4572 331 AnnotationArray** ConstMethod::method_annotations_addr() const {
coleenp@4572 332 assert(has_method_annotations(), "should only be called if method annotations are present");
coleenp@4572 333 return (AnnotationArray**)constMethod_end() - 1;
coleenp@4572 334 }
coleenp@4572 335
coleenp@4572 336 AnnotationArray** ConstMethod::parameter_annotations_addr() const {
coleenp@4572 337 assert(has_parameter_annotations(), "should only be called if method parameter annotations are present");
coleenp@4572 338 int offset = 1;
coleenp@4572 339 if (has_method_annotations()) offset++;
coleenp@4572 340 return (AnnotationArray**)constMethod_end() - offset;
coleenp@4572 341 }
coleenp@4572 342
coleenp@4572 343 AnnotationArray** ConstMethod::type_annotations_addr() const {
coleenp@4572 344 assert(has_type_annotations(), "should only be called if method type annotations are present");
coleenp@4572 345 int offset = 1;
coleenp@4572 346 if (has_method_annotations()) offset++;
coleenp@4572 347 if (has_parameter_annotations()) offset++;
coleenp@4572 348 return (AnnotationArray**)constMethod_end() - offset;
coleenp@4572 349 }
coleenp@4572 350
coleenp@4572 351 AnnotationArray** ConstMethod::default_annotations_addr() const {
coleenp@4572 352 assert(has_default_annotations(), "should only be called if method default annotations are present");
coleenp@4572 353 int offset = 1;
coleenp@4572 354 if (has_method_annotations()) offset++;
coleenp@4572 355 if (has_parameter_annotations()) offset++;
coleenp@4572 356 if (has_type_annotations()) offset++;
coleenp@4572 357 return (AnnotationArray**)constMethod_end() - offset;
coleenp@4572 358 }
coleenp@4037 359
coleenp@4037 360 // Printing
coleenp@4037 361
coleenp@4037 362 void ConstMethod::print_on(outputStream* st) const {
coleenp@4037 363 ResourceMark rm;
coleenp@4037 364 assert(is_constMethod(), "must be constMethod");
coleenp@4037 365 st->print_cr(internal_name());
coleenp@4037 366 st->print(" - method: " INTPTR_FORMAT " ", (address)method());
coleenp@4037 367 method()->print_value_on(st); st->cr();
coleenp@4037 368 if (has_stackmap_table()) {
coleenp@4037 369 st->print(" - stackmap data: ");
coleenp@4037 370 stackmap_data()->print_value_on(st);
coleenp@4037 371 st->cr();
coleenp@4037 372 }
coleenp@4037 373 }
coleenp@4037 374
coleenp@4037 375 // Short version of printing ConstMethod* - just print the name of the
coleenp@4037 376 // method it belongs to.
coleenp@4037 377 void ConstMethod::print_value_on(outputStream* st) const {
coleenp@4037 378 assert(is_constMethod(), "must be constMethod");
coleenp@4037 379 st->print(" const part of method " );
coleenp@4037 380 method()->print_value_on(st);
coleenp@4037 381 }
coleenp@4037 382
acorn@4497 383 #if INCLUDE_SERVICES
acorn@4497 384 // Size Statistics
acorn@4497 385 void ConstMethod::collect_statistics(KlassSizeStats *sz) const {
acorn@4497 386 int n1, n2, n3;
acorn@4497 387 sz->_const_method_bytes += (n1 = sz->count(this));
acorn@4497 388 sz->_bytecode_bytes += (n2 = code_size());
acorn@4497 389 sz->_stackmap_bytes += (n3 = sz->count_array(stackmap_data()));
acorn@4497 390
coleenp@4572 391 // Count method annotations
coleenp@4572 392 int a1 = 0, a2 = 0, a3 = 0, a4 = 0;
coleenp@4572 393 if (has_method_annotations()) {
coleenp@4572 394 sz->_methods_annotations_bytes += (a1 = sz->count_array(method_annotations()));
coleenp@4572 395 }
coleenp@4572 396 if (has_parameter_annotations()) {
coleenp@4572 397 sz->_methods_parameter_annotations_bytes += (a2 = sz->count_array(parameter_annotations()));
coleenp@4572 398 }
coleenp@4572 399 if (has_type_annotations()) {
coleenp@4572 400 sz->_methods_type_annotations_bytes += (a3 = sz->count_array(type_annotations()));
coleenp@4572 401 }
coleenp@4572 402 if (has_default_annotations()) {
coleenp@4572 403 sz->_methods_default_annotations_bytes += (a4 = sz->count_array(default_annotations()));
coleenp@4572 404 }
coleenp@4572 405
coleenp@4572 406 int size_annotations = a1 + a2 + a3 + a4;
coleenp@4572 407
coleenp@4572 408 sz->_method_all_bytes += n1 + n3 + size_annotations; // note: n2 is part of n3
coleenp@4572 409 sz->_ro_bytes += n1 + n3 + size_annotations;
acorn@4497 410 }
acorn@4497 411 #endif // INCLUDE_SERVICES
coleenp@4037 412
coleenp@4037 413 // Verification
coleenp@4037 414
coleenp@4037 415 void ConstMethod::verify_on(outputStream* st) {
coleenp@4037 416 guarantee(is_constMethod(), "object must be constMethod");
coleenp@4037 417 guarantee(is_metadata(), err_msg("Should be metadata " PTR_FORMAT, this));
coleenp@4037 418
coleenp@4037 419 // Verification can occur during oop construction before the method or
coleenp@4037 420 // other fields have been initialized.
coleenp@4037 421 guarantee(method()->is_method(), "should be method");
coleenp@4037 422
coleenp@4572 423 address m_end = (address)((intptr_t) this + size());
coleenp@4037 424 address compressed_table_start = code_end();
coleenp@4037 425 guarantee(compressed_table_start <= m_end, "invalid method layout");
coleenp@4037 426 address compressed_table_end = compressed_table_start;
coleenp@4037 427 // Verify line number table
coleenp@4037 428 if (has_linenumber_table()) {
coleenp@4037 429 CompressedLineNumberReadStream stream(compressed_linenumber_table());
coleenp@4037 430 while (stream.read_pair()) {
coleenp@4037 431 guarantee(stream.bci() >= 0 && stream.bci() <= code_size(), "invalid bci in line number table");
coleenp@4037 432 }
coleenp@4037 433 compressed_table_end += stream.position();
coleenp@4037 434 }
coleenp@4037 435 guarantee(compressed_table_end <= m_end, "invalid method layout");
coleenp@4037 436 // Verify checked exceptions, exception table and local variable tables
coleenp@4398 437 if (has_method_parameters()) {
coleenp@4398 438 u2* addr = method_parameters_length_addr();
coleenp@4398 439 guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout");
coleenp@4398 440 }
coleenp@4037 441 if (has_checked_exceptions()) {
coleenp@4037 442 u2* addr = checked_exceptions_length_addr();
coleenp@4037 443 guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout");
coleenp@4037 444 }
coleenp@4037 445 if (has_exception_handler()) {
coleenp@4037 446 u2* addr = exception_table_length_addr();
coleenp@4037 447 guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout");
coleenp@4037 448 }
coleenp@4037 449 if (has_localvariable_table()) {
coleenp@4037 450 u2* addr = localvariable_table_length_addr();
coleenp@4037 451 guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout");
coleenp@4037 452 }
coleenp@4037 453 // Check compressed_table_end relative to uncompressed_table_start
coleenp@4037 454 u2* uncompressed_table_start;
coleenp@4037 455 if (has_localvariable_table()) {
coleenp@4037 456 uncompressed_table_start = (u2*) localvariable_table_start();
coleenp@4037 457 } else if (has_exception_handler()) {
coleenp@4037 458 uncompressed_table_start = (u2*) exception_table_start();
coleenp@4037 459 } else if (has_checked_exceptions()) {
coleenp@4037 460 uncompressed_table_start = (u2*) checked_exceptions_start();
coleenp@4398 461 } else if (has_method_parameters()) {
coleenp@4398 462 uncompressed_table_start = (u2*) method_parameters_start();
coleenp@4037 463 } else {
coleenp@4037 464 uncompressed_table_start = (u2*) m_end;
coleenp@4037 465 }
coleenp@4037 466 int gap = (intptr_t) uncompressed_table_start - (intptr_t) compressed_table_end;
coleenp@4037 467 int max_gap = align_object_size(1)*BytesPerWord;
coleenp@4037 468 guarantee(gap >= 0 && gap < max_gap, "invalid method layout");
coleenp@4037 469 }

mercurial