src/share/vm/oops/constMethod.cpp

Mon, 12 Aug 2019 18:30:40 +0300

author
apetushkov
date
Mon, 12 Aug 2019 18:30:40 +0300
changeset 9858
b985cbb00e68
parent 8768
c648545660d7
child 8856
ac27a9c85bea
permissions
-rw-r--r--

8223147: JFR Backport
8199712: Flight Recorder
8203346: JFR: Inconsistent signature of jfr_add_string_constant
8195817: JFR.stop should require name of recording
8195818: JFR.start should increase autogenerated name by one
8195819: Remove recording=x from jcmd JFR.check output
8203921: JFR thread sampling is missing fixes from JDK-8194552
8203929: Limit amount of data for JFR.dump
8203664: JFR start failure after AppCDS archive created with JFR StartFlightRecording
8003209: JFR events for network utilization
8207392: [PPC64] Implement JFR profiling
8202835: jfr/event/os/TestSystemProcess.java fails on missing events
Summary: Backport JFR from JDK11. Initial integration
Reviewed-by: neugens

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

mercurial