src/share/vm/oops/constMethod.cpp

Sat, 07 Nov 2020 10:30:02 +0800

author
aoqi
date
Sat, 07 Nov 2020 10:30:02 +0800
changeset 10026
8c95980d0b66
parent 8856
ac27a9c85bea
permissions
-rw-r--r--

Added tag mips-jdk8u275-b01 for changeset d3b4d62f391f

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

mercurial