src/share/vm/oops/constMethod.cpp

Fri, 08 Mar 2013 11:47:57 -0500

author
coleenp
date
Fri, 08 Mar 2013 11:47:57 -0500
changeset 4712
3efdfd6ddbf2
parent 4572
927a311d00f9
child 4715
5939f5953b45
permissions
-rw-r--r--

8003553: NPG: metaspace objects should be zeroed in constructors
Summary: Zero metadata in constructors, not in allocation (and some in constructors)
Reviewed-by: jmasa, sspitsyn

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

mercurial