src/share/vm/oops/constMethod.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial