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