annotate src/share/vm/oops/constMethod.cpp @ 5645:fce21ac5968d

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