annotate src/share/vm/classfile/classFileParser.cpp @ 975:83c29a26f67c

6879572: SA fails _is_marked_dependent not found Reviewed-by: kamg, dcubed
author acorn
date Wed, 16 Sep 2009 15:42:46 -0400
parents 26b774d693aa
children 74a5db69c1fe
rev   line source
duke@0 1 /*
xdono@579 2 * Copyright 1997-2009 Sun Microsystems, Inc. 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 *
duke@0 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@0 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@0 21 * have any questions.
duke@0 22 *
duke@0 23 */
duke@0 24
duke@0 25 #include "incls/_precompiled.incl"
duke@0 26 #include "incls/_classFileParser.cpp.incl"
duke@0 27
duke@0 28 // We generally try to create the oops directly when parsing, rather than allocating
duke@0 29 // temporary data structures and copying the bytes twice. A temporary area is only
duke@0 30 // needed when parsing utf8 entries in the constant pool and when parsing line number
duke@0 31 // tables.
duke@0 32
duke@0 33 // We add assert in debug mode when class format is not checked.
duke@0 34
duke@0 35 #define JAVA_CLASSFILE_MAGIC 0xCAFEBABE
duke@0 36 #define JAVA_MIN_SUPPORTED_VERSION 45
kamg@136 37 #define JAVA_MAX_SUPPORTED_VERSION 51
duke@0 38 #define JAVA_MAX_SUPPORTED_MINOR_VERSION 0
duke@0 39
duke@0 40 // Used for two backward compatibility reasons:
duke@0 41 // - to check for new additions to the class file format in JDK1.5
duke@0 42 // - to check for bug fixes in the format checker in JDK1.5
duke@0 43 #define JAVA_1_5_VERSION 49
duke@0 44
duke@0 45 // Used for backward compatibility reasons:
duke@0 46 // - to check for javac bug fixes that happened after 1.5
kamg@176 47 // - also used as the max version when running in jdk6
duke@0 48 #define JAVA_6_VERSION 50
duke@0 49
duke@0 50
duke@0 51 void ClassFileParser::parse_constant_pool_entries(constantPoolHandle cp, int length, TRAPS) {
duke@0 52 // Use a local copy of ClassFileStream. It helps the C++ compiler to optimize
duke@0 53 // this function (_current can be allocated in a register, with scalar
duke@0 54 // replacement of aggregates). The _current pointer is copied back to
duke@0 55 // stream() when this function returns. DON'T call another method within
duke@0 56 // this method that uses stream().
duke@0 57 ClassFileStream* cfs0 = stream();
duke@0 58 ClassFileStream cfs1 = *cfs0;
duke@0 59 ClassFileStream* cfs = &cfs1;
duke@0 60 #ifdef ASSERT
duke@0 61 u1* old_current = cfs0->current();
duke@0 62 #endif
duke@0 63
duke@0 64 // Used for batching symbol allocations.
duke@0 65 const char* names[SymbolTable::symbol_alloc_batch_size];
duke@0 66 int lengths[SymbolTable::symbol_alloc_batch_size];
duke@0 67 int indices[SymbolTable::symbol_alloc_batch_size];
duke@0 68 unsigned int hashValues[SymbolTable::symbol_alloc_batch_size];
duke@0 69 int names_count = 0;
duke@0 70
duke@0 71 // parsing Index 0 is unused
duke@0 72 for (int index = 1; index < length; index++) {
duke@0 73 // Each of the following case guarantees one more byte in the stream
duke@0 74 // for the following tag or the access_flags following constant pool,
duke@0 75 // so we don't need bounds-check for reading tag.
duke@0 76 u1 tag = cfs->get_u1_fast();
duke@0 77 switch (tag) {
duke@0 78 case JVM_CONSTANT_Class :
duke@0 79 {
duke@0 80 cfs->guarantee_more(3, CHECK); // name_index, tag/access_flags
duke@0 81 u2 name_index = cfs->get_u2_fast();
duke@0 82 cp->klass_index_at_put(index, name_index);
duke@0 83 }
duke@0 84 break;
duke@0 85 case JVM_CONSTANT_Fieldref :
duke@0 86 {
duke@0 87 cfs->guarantee_more(5, CHECK); // class_index, name_and_type_index, tag/access_flags
duke@0 88 u2 class_index = cfs->get_u2_fast();
duke@0 89 u2 name_and_type_index = cfs->get_u2_fast();
duke@0 90 cp->field_at_put(index, class_index, name_and_type_index);
duke@0 91 }
duke@0 92 break;
duke@0 93 case JVM_CONSTANT_Methodref :
duke@0 94 {
duke@0 95 cfs->guarantee_more(5, CHECK); // class_index, name_and_type_index, tag/access_flags
duke@0 96 u2 class_index = cfs->get_u2_fast();
duke@0 97 u2 name_and_type_index = cfs->get_u2_fast();
duke@0 98 cp->method_at_put(index, class_index, name_and_type_index);
duke@0 99 }
duke@0 100 break;
duke@0 101 case JVM_CONSTANT_InterfaceMethodref :
duke@0 102 {
duke@0 103 cfs->guarantee_more(5, CHECK); // class_index, name_and_type_index, tag/access_flags
duke@0 104 u2 class_index = cfs->get_u2_fast();
duke@0 105 u2 name_and_type_index = cfs->get_u2_fast();
duke@0 106 cp->interface_method_at_put(index, class_index, name_and_type_index);
duke@0 107 }
duke@0 108 break;
duke@0 109 case JVM_CONSTANT_String :
duke@0 110 {
duke@0 111 cfs->guarantee_more(3, CHECK); // string_index, tag/access_flags
duke@0 112 u2 string_index = cfs->get_u2_fast();
duke@0 113 cp->string_index_at_put(index, string_index);
duke@0 114 }
duke@0 115 break;
duke@0 116 case JVM_CONSTANT_Integer :
duke@0 117 {
duke@0 118 cfs->guarantee_more(5, CHECK); // bytes, tag/access_flags
duke@0 119 u4 bytes = cfs->get_u4_fast();
duke@0 120 cp->int_at_put(index, (jint) bytes);
duke@0 121 }
duke@0 122 break;
duke@0 123 case JVM_CONSTANT_Float :
duke@0 124 {
duke@0 125 cfs->guarantee_more(5, CHECK); // bytes, tag/access_flags
duke@0 126 u4 bytes = cfs->get_u4_fast();
duke@0 127 cp->float_at_put(index, *(jfloat*)&bytes);
duke@0 128 }
duke@0 129 break;
duke@0 130 case JVM_CONSTANT_Long :
duke@0 131 // A mangled type might cause you to overrun allocated memory
duke@0 132 guarantee_property(index+1 < length,
duke@0 133 "Invalid constant pool entry %u in class file %s",
duke@0 134 index, CHECK);
duke@0 135 {
duke@0 136 cfs->guarantee_more(9, CHECK); // bytes, tag/access_flags
duke@0 137 u8 bytes = cfs->get_u8_fast();
duke@0 138 cp->long_at_put(index, bytes);
duke@0 139 }
duke@0 140 index++; // Skip entry following eigth-byte constant, see JVM book p. 98
duke@0 141 break;
duke@0 142 case JVM_CONSTANT_Double :
duke@0 143 // A mangled type might cause you to overrun allocated memory
duke@0 144 guarantee_property(index+1 < length,
duke@0 145 "Invalid constant pool entry %u in class file %s",
duke@0 146 index, CHECK);
duke@0 147 {
duke@0 148 cfs->guarantee_more(9, CHECK); // bytes, tag/access_flags
duke@0 149 u8 bytes = cfs->get_u8_fast();
duke@0 150 cp->double_at_put(index, *(jdouble*)&bytes);
duke@0 151 }
duke@0 152 index++; // Skip entry following eigth-byte constant, see JVM book p. 98
duke@0 153 break;
duke@0 154 case JVM_CONSTANT_NameAndType :
duke@0 155 {
duke@0 156 cfs->guarantee_more(5, CHECK); // name_index, signature_index, tag/access_flags
duke@0 157 u2 name_index = cfs->get_u2_fast();
duke@0 158 u2 signature_index = cfs->get_u2_fast();
duke@0 159 cp->name_and_type_at_put(index, name_index, signature_index);
duke@0 160 }
duke@0 161 break;
duke@0 162 case JVM_CONSTANT_Utf8 :
duke@0 163 {
duke@0 164 cfs->guarantee_more(2, CHECK); // utf8_length
duke@0 165 u2 utf8_length = cfs->get_u2_fast();
duke@0 166 u1* utf8_buffer = cfs->get_u1_buffer();
duke@0 167 assert(utf8_buffer != NULL, "null utf8 buffer");
duke@0 168 // Got utf8 string, guarantee utf8_length+1 bytes, set stream position forward.
duke@0 169 cfs->guarantee_more(utf8_length+1, CHECK); // utf8 string, tag/access_flags
duke@0 170 cfs->skip_u1_fast(utf8_length);
jrose@431 171
duke@0 172 // Before storing the symbol, make sure it's legal
duke@0 173 if (_need_verify) {
duke@0 174 verify_legal_utf8((unsigned char*)utf8_buffer, utf8_length, CHECK);
duke@0 175 }
duke@0 176
jrose@431 177 if (AnonymousClasses && has_cp_patch_at(index)) {
jrose@431 178 Handle patch = clear_cp_patch_at(index);
jrose@431 179 guarantee_property(java_lang_String::is_instance(patch()),
jrose@431 180 "Illegal utf8 patch at %d in class file %s",
jrose@431 181 index, CHECK);
jrose@431 182 char* str = java_lang_String::as_utf8_string(patch());
jrose@431 183 // (could use java_lang_String::as_symbol instead, but might as well batch them)
jrose@431 184 utf8_buffer = (u1*) str;
jrose@431 185 utf8_length = (int) strlen(str);
jrose@431 186 }
jrose@431 187
duke@0 188 unsigned int hash;
duke@0 189 symbolOop result = SymbolTable::lookup_only((char*)utf8_buffer, utf8_length, hash);
duke@0 190 if (result == NULL) {
duke@0 191 names[names_count] = (char*)utf8_buffer;
duke@0 192 lengths[names_count] = utf8_length;
duke@0 193 indices[names_count] = index;
duke@0 194 hashValues[names_count++] = hash;
duke@0 195 if (names_count == SymbolTable::symbol_alloc_batch_size) {
duke@0 196 oopFactory::new_symbols(cp, names_count, names, lengths, indices, hashValues, CHECK);
duke@0 197 names_count = 0;
duke@0 198 }
duke@0 199 } else {
duke@0 200 cp->symbol_at_put(index, result);
duke@0 201 }
duke@0 202 }
duke@0 203 break;
duke@0 204 default:
duke@0 205 classfile_parse_error(
duke@0 206 "Unknown constant tag %u in class file %s", tag, CHECK);
duke@0 207 break;
duke@0 208 }
duke@0 209 }
duke@0 210
duke@0 211 // Allocate the remaining symbols
duke@0 212 if (names_count > 0) {
duke@0 213 oopFactory::new_symbols(cp, names_count, names, lengths, indices, hashValues, CHECK);
duke@0 214 }
duke@0 215
duke@0 216 // Copy _current pointer of local copy back to stream().
duke@0 217 #ifdef ASSERT
duke@0 218 assert(cfs0->current() == old_current, "non-exclusive use of stream()");
duke@0 219 #endif
duke@0 220 cfs0->set_current(cfs1.current());
duke@0 221 }
duke@0 222
duke@0 223 bool inline valid_cp_range(int index, int length) { return (index > 0 && index < length); }
duke@0 224
duke@0 225 constantPoolHandle ClassFileParser::parse_constant_pool(TRAPS) {
duke@0 226 ClassFileStream* cfs = stream();
duke@0 227 constantPoolHandle nullHandle;
duke@0 228
duke@0 229 cfs->guarantee_more(3, CHECK_(nullHandle)); // length, first cp tag
duke@0 230 u2 length = cfs->get_u2_fast();
duke@0 231 guarantee_property(
duke@0 232 length >= 1, "Illegal constant pool size %u in class file %s",
duke@0 233 length, CHECK_(nullHandle));
duke@0 234 constantPoolOop constant_pool =
jmasa@518 235 oopFactory::new_constantPool(length,
jmasa@518 236 methodOopDesc::IsSafeConc,
jmasa@518 237 CHECK_(nullHandle));
duke@0 238 constantPoolHandle cp (THREAD, constant_pool);
duke@0 239
duke@0 240 cp->set_partially_loaded(); // Enables heap verify to work on partial constantPoolOops
duke@0 241
duke@0 242 // parsing constant pool entries
duke@0 243 parse_constant_pool_entries(cp, length, CHECK_(nullHandle));
duke@0 244
duke@0 245 int index = 1; // declared outside of loops for portability
duke@0 246
duke@0 247 // first verification pass - validate cross references and fixup class and string constants
duke@0 248 for (index = 1; index < length; index++) { // Index 0 is unused
duke@0 249 switch (cp->tag_at(index).value()) {
duke@0 250 case JVM_CONSTANT_Class :
duke@0 251 ShouldNotReachHere(); // Only JVM_CONSTANT_ClassIndex should be present
duke@0 252 break;
duke@0 253 case JVM_CONSTANT_Fieldref :
duke@0 254 // fall through
duke@0 255 case JVM_CONSTANT_Methodref :
duke@0 256 // fall through
duke@0 257 case JVM_CONSTANT_InterfaceMethodref : {
duke@0 258 if (!_need_verify) break;
duke@0 259 int klass_ref_index = cp->klass_ref_index_at(index);
duke@0 260 int name_and_type_ref_index = cp->name_and_type_ref_index_at(index);
duke@0 261 check_property(valid_cp_range(klass_ref_index, length) &&
jrose@431 262 is_klass_reference(cp, klass_ref_index),
duke@0 263 "Invalid constant pool index %u in class file %s",
duke@0 264 klass_ref_index,
duke@0 265 CHECK_(nullHandle));
duke@0 266 check_property(valid_cp_range(name_and_type_ref_index, length) &&
duke@0 267 cp->tag_at(name_and_type_ref_index).is_name_and_type(),
duke@0 268 "Invalid constant pool index %u in class file %s",
duke@0 269 name_and_type_ref_index,
duke@0 270 CHECK_(nullHandle));
duke@0 271 break;
duke@0 272 }
duke@0 273 case JVM_CONSTANT_String :
duke@0 274 ShouldNotReachHere(); // Only JVM_CONSTANT_StringIndex should be present
duke@0 275 break;
duke@0 276 case JVM_CONSTANT_Integer :
duke@0 277 break;
duke@0 278 case JVM_CONSTANT_Float :
duke@0 279 break;
duke@0 280 case JVM_CONSTANT_Long :
duke@0 281 case JVM_CONSTANT_Double :
duke@0 282 index++;
duke@0 283 check_property(
duke@0 284 (index < length && cp->tag_at(index).is_invalid()),
duke@0 285 "Improper constant pool long/double index %u in class file %s",
duke@0 286 index, CHECK_(nullHandle));
duke@0 287 break;
duke@0 288 case JVM_CONSTANT_NameAndType : {
duke@0 289 if (!_need_verify) break;
duke@0 290 int name_ref_index = cp->name_ref_index_at(index);
duke@0 291 int signature_ref_index = cp->signature_ref_index_at(index);
duke@0 292 check_property(
duke@0 293 valid_cp_range(name_ref_index, length) &&
duke@0 294 cp->tag_at(name_ref_index).is_utf8(),
duke@0 295 "Invalid constant pool index %u in class file %s",
duke@0 296 name_ref_index, CHECK_(nullHandle));
duke@0 297 check_property(
duke@0 298 valid_cp_range(signature_ref_index, length) &&
duke@0 299 cp->tag_at(signature_ref_index).is_utf8(),
duke@0 300 "Invalid constant pool index %u in class file %s",
duke@0 301 signature_ref_index, CHECK_(nullHandle));
duke@0 302 break;
duke@0 303 }
duke@0 304 case JVM_CONSTANT_Utf8 :
duke@0 305 break;
duke@0 306 case JVM_CONSTANT_UnresolvedClass : // fall-through
duke@0 307 case JVM_CONSTANT_UnresolvedClassInError:
duke@0 308 ShouldNotReachHere(); // Only JVM_CONSTANT_ClassIndex should be present
duke@0 309 break;
duke@0 310 case JVM_CONSTANT_ClassIndex :
duke@0 311 {
duke@0 312 int class_index = cp->klass_index_at(index);
duke@0 313 check_property(
duke@0 314 valid_cp_range(class_index, length) &&
duke@0 315 cp->tag_at(class_index).is_utf8(),
duke@0 316 "Invalid constant pool index %u in class file %s",
duke@0 317 class_index, CHECK_(nullHandle));
duke@0 318 cp->unresolved_klass_at_put(index, cp->symbol_at(class_index));
duke@0 319 }
duke@0 320 break;
duke@0 321 case JVM_CONSTANT_UnresolvedString :
duke@0 322 ShouldNotReachHere(); // Only JVM_CONSTANT_StringIndex should be present
duke@0 323 break;
duke@0 324 case JVM_CONSTANT_StringIndex :
duke@0 325 {
duke@0 326 int string_index = cp->string_index_at(index);
duke@0 327 check_property(
duke@0 328 valid_cp_range(string_index, length) &&
duke@0 329 cp->tag_at(string_index).is_utf8(),
duke@0 330 "Invalid constant pool index %u in class file %s",
duke@0 331 string_index, CHECK_(nullHandle));
duke@0 332 symbolOop sym = cp->symbol_at(string_index);
duke@0 333 cp->unresolved_string_at_put(index, sym);
duke@0 334 }
duke@0 335 break;
duke@0 336 default:
duke@0 337 fatal1("bad constant pool tag value %u", cp->tag_at(index).value());
duke@0 338 ShouldNotReachHere();
duke@0 339 break;
duke@0 340 } // end of switch
duke@0 341 } // end of for
duke@0 342
jrose@431 343 if (_cp_patches != NULL) {
jrose@431 344 // need to treat this_class specially...
jrose@431 345 assert(AnonymousClasses, "");
jrose@431 346 int this_class_index;
jrose@431 347 {
jrose@431 348 cfs->guarantee_more(8, CHECK_(nullHandle)); // flags, this_class, super_class, infs_len
jrose@431 349 u1* mark = cfs->current();
jrose@431 350 u2 flags = cfs->get_u2_fast();
jrose@431 351 this_class_index = cfs->get_u2_fast();
jrose@431 352 cfs->set_current(mark); // revert to mark
jrose@431 353 }
jrose@431 354
jrose@431 355 for (index = 1; index < length; index++) { // Index 0 is unused
jrose@431 356 if (has_cp_patch_at(index)) {
jrose@431 357 guarantee_property(index != this_class_index,
jrose@431 358 "Illegal constant pool patch to self at %d in class file %s",
jrose@431 359 index, CHECK_(nullHandle));
jrose@431 360 patch_constant_pool(cp, index, cp_patch_at(index), CHECK_(nullHandle));
jrose@431 361 }
jrose@431 362 }
jrose@431 363 // Ensure that all the patches have been used.
jrose@431 364 for (index = 0; index < _cp_patches->length(); index++) {
jrose@431 365 guarantee_property(!has_cp_patch_at(index),
jrose@431 366 "Unused constant pool patch at %d in class file %s",
jrose@431 367 index, CHECK_(nullHandle));
jrose@431 368 }
jrose@431 369 }
jrose@431 370
duke@0 371 if (!_need_verify) {
duke@0 372 return cp;
duke@0 373 }
duke@0 374
duke@0 375 // second verification pass - checks the strings are of the right format.
jrose@431 376 // but not yet to the other entries
duke@0 377 for (index = 1; index < length; index++) {
duke@0 378 jbyte tag = cp->tag_at(index).value();
duke@0 379 switch (tag) {
duke@0 380 case JVM_CONSTANT_UnresolvedClass: {
duke@0 381 symbolHandle class_name(THREAD, cp->unresolved_klass_at(index));
jrose@431 382 // check the name, even if _cp_patches will overwrite it
duke@0 383 verify_legal_class_name(class_name, CHECK_(nullHandle));
duke@0 384 break;
duke@0 385 }
duke@0 386 case JVM_CONSTANT_Fieldref:
duke@0 387 case JVM_CONSTANT_Methodref:
duke@0 388 case JVM_CONSTANT_InterfaceMethodref: {
duke@0 389 int name_and_type_ref_index = cp->name_and_type_ref_index_at(index);
duke@0 390 // already verified to be utf8
duke@0 391 int name_ref_index = cp->name_ref_index_at(name_and_type_ref_index);
duke@0 392 // already verified to be utf8
duke@0 393 int signature_ref_index = cp->signature_ref_index_at(name_and_type_ref_index);
duke@0 394 symbolHandle name(THREAD, cp->symbol_at(name_ref_index));
duke@0 395 symbolHandle signature(THREAD, cp->symbol_at(signature_ref_index));
duke@0 396 if (tag == JVM_CONSTANT_Fieldref) {
duke@0 397 verify_legal_field_name(name, CHECK_(nullHandle));
duke@0 398 verify_legal_field_signature(name, signature, CHECK_(nullHandle));
duke@0 399 } else {
duke@0 400 verify_legal_method_name(name, CHECK_(nullHandle));
duke@0 401 verify_legal_method_signature(name, signature, CHECK_(nullHandle));
duke@0 402 if (tag == JVM_CONSTANT_Methodref) {
duke@0 403 // 4509014: If a class method name begins with '<', it must be "<init>".
duke@0 404 assert(!name.is_null(), "method name in constant pool is null");
duke@0 405 unsigned int name_len = name->utf8_length();
duke@0 406 assert(name_len > 0, "bad method name"); // already verified as legal name
duke@0 407 if (name->byte_at(0) == '<') {
duke@0 408 if (name() != vmSymbols::object_initializer_name()) {
duke@0 409 classfile_parse_error(
duke@0 410 "Bad method name at constant pool index %u in class file %s",
duke@0 411 name_ref_index, CHECK_(nullHandle));
duke@0 412 }
duke@0 413 }
duke@0 414 }
duke@0 415 }
duke@0 416 break;
duke@0 417 }
duke@0 418 } // end of switch
duke@0 419 } // end of for
duke@0 420
duke@0 421 return cp;
duke@0 422 }
duke@0 423
duke@0 424
jrose@431 425 void ClassFileParser::patch_constant_pool(constantPoolHandle cp, int index, Handle patch, TRAPS) {
jrose@431 426 assert(AnonymousClasses, "");
jrose@431 427 BasicType patch_type = T_VOID;
jrose@431 428 switch (cp->tag_at(index).value()) {
jrose@431 429
jrose@431 430 case JVM_CONSTANT_UnresolvedClass :
jrose@431 431 // Patching a class means pre-resolving it.
jrose@431 432 // The name in the constant pool is ignored.
jrose@431 433 if (patch->klass() == SystemDictionary::class_klass()) { // %%% java_lang_Class::is_instance
jrose@431 434 guarantee_property(!java_lang_Class::is_primitive(patch()),
jrose@431 435 "Illegal class patch at %d in class file %s",
jrose@431 436 index, CHECK);
jrose@431 437 cp->klass_at_put(index, java_lang_Class::as_klassOop(patch()));
jrose@431 438 } else {
jrose@431 439 guarantee_property(java_lang_String::is_instance(patch()),
jrose@431 440 "Illegal class patch at %d in class file %s",
jrose@431 441 index, CHECK);
jrose@431 442 symbolHandle name = java_lang_String::as_symbol(patch(), CHECK);
jrose@431 443 cp->unresolved_klass_at_put(index, name());
jrose@431 444 }
jrose@431 445 break;
jrose@431 446
jrose@431 447 case JVM_CONSTANT_UnresolvedString :
jrose@431 448 // Patching a string means pre-resolving it.
jrose@431 449 // The spelling in the constant pool is ignored.
jrose@431 450 // The constant reference may be any object whatever.
jrose@431 451 // If it is not a real interned string, the constant is referred
jrose@431 452 // to as a "pseudo-string", and must be presented to the CP
jrose@431 453 // explicitly, because it may require scavenging.
jrose@431 454 cp->pseudo_string_at_put(index, patch());
jrose@431 455 break;
jrose@431 456
jrose@431 457 case JVM_CONSTANT_Integer : patch_type = T_INT; goto patch_prim;
jrose@431 458 case JVM_CONSTANT_Float : patch_type = T_FLOAT; goto patch_prim;
jrose@431 459 case JVM_CONSTANT_Long : patch_type = T_LONG; goto patch_prim;
jrose@431 460 case JVM_CONSTANT_Double : patch_type = T_DOUBLE; goto patch_prim;
jrose@431 461 patch_prim:
jrose@431 462 {
jrose@431 463 jvalue value;
jrose@431 464 BasicType value_type = java_lang_boxing_object::get_value(patch(), &value);
jrose@431 465 guarantee_property(value_type == patch_type,
jrose@431 466 "Illegal primitive patch at %d in class file %s",
jrose@431 467 index, CHECK);
jrose@431 468 switch (value_type) {
jrose@431 469 case T_INT: cp->int_at_put(index, value.i); break;
jrose@431 470 case T_FLOAT: cp->float_at_put(index, value.f); break;
jrose@431 471 case T_LONG: cp->long_at_put(index, value.j); break;
jrose@431 472 case T_DOUBLE: cp->double_at_put(index, value.d); break;
jrose@431 473 default: assert(false, "");
jrose@431 474 }
jrose@431 475 }
jrose@431 476 break;
jrose@431 477
jrose@431 478 default:
jrose@431 479 // %%% TODO: put method handles into CONSTANT_InterfaceMethodref, etc.
jrose@431 480 guarantee_property(!has_cp_patch_at(index),
jrose@431 481 "Illegal unexpected patch at %d in class file %s",
jrose@431 482 index, CHECK);
jrose@431 483 return;
jrose@431 484 }
jrose@431 485
jrose@431 486 // On fall-through, mark the patch as used.
jrose@431 487 clear_cp_patch_at(index);
jrose@431 488 }
jrose@431 489
jrose@431 490
jrose@431 491
duke@0 492 class NameSigHash: public ResourceObj {
duke@0 493 public:
duke@0 494 symbolOop _name; // name
duke@0 495 symbolOop _sig; // signature
duke@0 496 NameSigHash* _next; // Next entry in hash table
duke@0 497 };
duke@0 498
duke@0 499
duke@0 500 #define HASH_ROW_SIZE 256
duke@0 501
duke@0 502 unsigned int hash(symbolOop name, symbolOop sig) {
duke@0 503 unsigned int raw_hash = 0;
duke@0 504 raw_hash += ((unsigned int)(uintptr_t)name) >> (LogHeapWordSize + 2);
duke@0 505 raw_hash += ((unsigned int)(uintptr_t)sig) >> LogHeapWordSize;
duke@0 506
duke@0 507 return (raw_hash + (unsigned int)(uintptr_t)name) % HASH_ROW_SIZE;
duke@0 508 }
duke@0 509
duke@0 510
duke@0 511 void initialize_hashtable(NameSigHash** table) {
duke@0 512 memset((void*)table, 0, sizeof(NameSigHash*) * HASH_ROW_SIZE);
duke@0 513 }
duke@0 514
duke@0 515 // Return false if the name/sig combination is found in table.
duke@0 516 // Return true if no duplicate is found. And name/sig is added as a new entry in table.
duke@0 517 // The old format checker uses heap sort to find duplicates.
duke@0 518 // NOTE: caller should guarantee that GC doesn't happen during the life cycle
duke@0 519 // of table since we don't expect symbolOop's to move.
duke@0 520 bool put_after_lookup(symbolOop name, symbolOop sig, NameSigHash** table) {
duke@0 521 assert(name != NULL, "name in constant pool is NULL");
duke@0 522
duke@0 523 // First lookup for duplicates
duke@0 524 int index = hash(name, sig);
duke@0 525 NameSigHash* entry = table[index];
duke@0 526 while (entry != NULL) {
duke@0 527 if (entry->_name == name && entry->_sig == sig) {
duke@0 528 return false;
duke@0 529 }
duke@0 530 entry = entry->_next;
duke@0 531 }
duke@0 532
duke@0 533 // No duplicate is found, allocate a new entry and fill it.
duke@0 534 entry = new NameSigHash();
duke@0 535 entry->_name = name;
duke@0 536 entry->_sig = sig;
duke@0 537
duke@0 538 // Insert into hash table
duke@0 539 entry->_next = table[index];
duke@0 540 table[index] = entry;
duke@0 541
duke@0 542 return true;
duke@0 543 }
duke@0 544
duke@0 545
duke@0 546 objArrayHandle ClassFileParser::parse_interfaces(constantPoolHandle cp,
duke@0 547 int length,
duke@0 548 Handle class_loader,
duke@0 549 Handle protection_domain,
duke@0 550 symbolHandle class_name,
duke@0 551 TRAPS) {
duke@0 552 ClassFileStream* cfs = stream();
duke@0 553 assert(length > 0, "only called for length>0");
duke@0 554 objArrayHandle nullHandle;
duke@0 555 objArrayOop interface_oop = oopFactory::new_system_objArray(length, CHECK_(nullHandle));
duke@0 556 objArrayHandle interfaces (THREAD, interface_oop);
duke@0 557
duke@0 558 int index;
duke@0 559 for (index = 0; index < length; index++) {
duke@0 560 u2 interface_index = cfs->get_u2(CHECK_(nullHandle));
jrose@431 561 KlassHandle interf;
duke@0 562 check_property(
duke@0 563 valid_cp_range(interface_index, cp->length()) &&
jrose@431 564 is_klass_reference(cp, interface_index),
duke@0 565 "Interface name has bad constant pool index %u in class file %s",
duke@0 566 interface_index, CHECK_(nullHandle));
jrose@431 567 if (cp->tag_at(interface_index).is_klass()) {
jrose@431 568 interf = KlassHandle(THREAD, cp->resolved_klass_at(interface_index));
jrose@431 569 } else {
jrose@431 570 symbolHandle unresolved_klass (THREAD, cp->klass_name_at(interface_index));
jrose@431 571
jrose@431 572 // Don't need to check legal name because it's checked when parsing constant pool.
jrose@431 573 // But need to make sure it's not an array type.
jrose@431 574 guarantee_property(unresolved_klass->byte_at(0) != JVM_SIGNATURE_ARRAY,
jrose@431 575 "Bad interface name in class file %s", CHECK_(nullHandle));
jrose@431 576
jrose@431 577 // Call resolve_super so classcircularity is checked
jrose@431 578 klassOop k = SystemDictionary::resolve_super_or_fail(class_name,
jrose@431 579 unresolved_klass, class_loader, protection_domain,
jrose@431 580 false, CHECK_(nullHandle));
jrose@431 581 interf = KlassHandle(THREAD, k);
jrose@431 582
jrose@474 583 if (LinkWellKnownClasses) // my super type is well known to me
jrose@474 584 cp->klass_at_put(interface_index, interf()); // eagerly resolve
jrose@431 585 }
duke@0 586
duke@0 587 if (!Klass::cast(interf())->is_interface()) {
duke@0 588 THROW_MSG_(vmSymbols::java_lang_IncompatibleClassChangeError(), "Implementing class", nullHandle);
duke@0 589 }
duke@0 590 interfaces->obj_at_put(index, interf());
duke@0 591 }
duke@0 592
duke@0 593 if (!_need_verify || length <= 1) {
duke@0 594 return interfaces;
duke@0 595 }
duke@0 596
duke@0 597 // Check if there's any duplicates in interfaces
duke@0 598 ResourceMark rm(THREAD);
duke@0 599 NameSigHash** interface_names = NEW_RESOURCE_ARRAY_IN_THREAD(
duke@0 600 THREAD, NameSigHash*, HASH_ROW_SIZE);
duke@0 601 initialize_hashtable(interface_names);
duke@0 602 bool dup = false;
duke@0 603 {
duke@0 604 debug_only(No_Safepoint_Verifier nsv;)
duke@0 605 for (index = 0; index < length; index++) {
duke@0 606 klassOop k = (klassOop)interfaces->obj_at(index);
duke@0 607 symbolOop name = instanceKlass::cast(k)->name();
duke@0 608 // If no duplicates, add (name, NULL) in hashtable interface_names.
duke@0 609 if (!put_after_lookup(name, NULL, interface_names)) {
duke@0 610 dup = true;
duke@0 611 break;
duke@0 612 }
duke@0 613 }
duke@0 614 }
duke@0 615 if (dup) {
duke@0 616 classfile_parse_error("Duplicate interface name in class file %s",
duke@0 617 CHECK_(nullHandle));
duke@0 618 }
duke@0 619
duke@0 620 return interfaces;
duke@0 621 }
duke@0 622
duke@0 623
duke@0 624 void ClassFileParser::verify_constantvalue(int constantvalue_index, int signature_index, constantPoolHandle cp, TRAPS) {
duke@0 625 // Make sure the constant pool entry is of a type appropriate to this field
duke@0 626 guarantee_property(
duke@0 627 (constantvalue_index > 0 &&
duke@0 628 constantvalue_index < cp->length()),
duke@0 629 "Bad initial value index %u in ConstantValue attribute in class file %s",
duke@0 630 constantvalue_index, CHECK);
duke@0 631 constantTag value_type = cp->tag_at(constantvalue_index);
duke@0 632 switch ( cp->basic_type_for_signature_at(signature_index) ) {
duke@0 633 case T_LONG:
duke@0 634 guarantee_property(value_type.is_long(), "Inconsistent constant value type in class file %s", CHECK);
duke@0 635 break;
duke@0 636 case T_FLOAT:
duke@0 637 guarantee_property(value_type.is_float(), "Inconsistent constant value type in class file %s", CHECK);
duke@0 638 break;
duke@0 639 case T_DOUBLE:
duke@0 640 guarantee_property(value_type.is_double(), "Inconsistent constant value type in class file %s", CHECK);
duke@0 641 break;
duke@0 642 case T_BYTE: case T_CHAR: case T_SHORT: case T_BOOLEAN: case T_INT:
duke@0 643 guarantee_property(value_type.is_int(), "Inconsistent constant value type in class file %s", CHECK);
duke@0 644 break;
duke@0 645 case T_OBJECT:
duke@0 646 guarantee_property((cp->symbol_at(signature_index)->equals("Ljava/lang/String;", 18)
duke@0 647 && (value_type.is_string() || value_type.is_unresolved_string())),
duke@0 648 "Bad string initial value in class file %s", CHECK);
duke@0 649 break;
duke@0 650 default:
duke@0 651 classfile_parse_error(
duke@0 652 "Unable to set initial value %u in class file %s",
duke@0 653 constantvalue_index, CHECK);
duke@0 654 }
duke@0 655 }
duke@0 656
duke@0 657
duke@0 658 // Parse attributes for a field.
duke@0 659 void ClassFileParser::parse_field_attributes(constantPoolHandle cp,
duke@0 660 u2 attributes_count,
duke@0 661 bool is_static, u2 signature_index,
duke@0 662 u2* constantvalue_index_addr,
duke@0 663 bool* is_synthetic_addr,
duke@0 664 u2* generic_signature_index_addr,
duke@0 665 typeArrayHandle* field_annotations,
duke@0 666 TRAPS) {
duke@0 667 ClassFileStream* cfs = stream();
duke@0 668 assert(attributes_count > 0, "length should be greater than 0");
duke@0 669 u2 constantvalue_index = 0;
duke@0 670 u2 generic_signature_index = 0;
duke@0 671 bool is_synthetic = false;
duke@0 672 u1* runtime_visible_annotations = NULL;
duke@0 673 int runtime_visible_annotations_length = 0;
duke@0 674 u1* runtime_invisible_annotations = NULL;
duke@0 675 int runtime_invisible_annotations_length = 0;
duke@0 676 while (attributes_count--) {
duke@0 677 cfs->guarantee_more(6, CHECK); // attribute_name_index, attribute_length
duke@0 678 u2 attribute_name_index = cfs->get_u2_fast();
duke@0 679 u4 attribute_length = cfs->get_u4_fast();
duke@0 680 check_property(valid_cp_range(attribute_name_index, cp->length()) &&
duke@0 681 cp->tag_at(attribute_name_index).is_utf8(),
duke@0 682 "Invalid field attribute index %u in class file %s",
duke@0 683 attribute_name_index,
duke@0 684 CHECK);
duke@0 685 symbolOop attribute_name = cp->symbol_at(attribute_name_index);
duke@0 686 if (is_static && attribute_name == vmSymbols::tag_constant_value()) {
duke@0 687 // ignore if non-static
duke@0 688 if (constantvalue_index != 0) {
duke@0 689 classfile_parse_error("Duplicate ConstantValue attribute in class file %s", CHECK);
duke@0 690 }
duke@0 691 check_property(
duke@0 692 attribute_length == 2,
duke@0 693 "Invalid ConstantValue field attribute length %u in class file %s",
duke@0 694 attribute_length, CHECK);
duke@0 695 constantvalue_index = cfs->get_u2(CHECK);
duke@0 696 if (_need_verify) {
duke@0 697 verify_constantvalue(constantvalue_index, signature_index, cp, CHECK);
duke@0 698 }
duke@0 699 } else if (attribute_name == vmSymbols::tag_synthetic()) {
duke@0 700 if (attribute_length != 0) {
duke@0 701 classfile_parse_error(
duke@0 702 "Invalid Synthetic field attribute length %u in class file %s",
duke@0 703 attribute_length, CHECK);
duke@0 704 }
duke@0 705 is_synthetic = true;
duke@0 706 } else if (attribute_name == vmSymbols::tag_deprecated()) { // 4276120
duke@0 707 if (attribute_length != 0) {
duke@0 708 classfile_parse_error(
duke@0 709 "Invalid Deprecated field attribute length %u in class file %s",
duke@0 710 attribute_length, CHECK);
duke@0 711 }
duke@0 712 } else if (_major_version >= JAVA_1_5_VERSION) {
duke@0 713 if (attribute_name == vmSymbols::tag_signature()) {
duke@0 714 if (attribute_length != 2) {
duke@0 715 classfile_parse_error(
duke@0 716 "Wrong size %u for field's Signature attribute in class file %s",
duke@0 717 attribute_length, CHECK);
duke@0 718 }
duke@0 719 generic_signature_index = cfs->get_u2(CHECK);
duke@0 720 } else if (attribute_name == vmSymbols::tag_runtime_visible_annotations()) {
duke@0 721 runtime_visible_annotations_length = attribute_length;
duke@0 722 runtime_visible_annotations = cfs->get_u1_buffer();
duke@0 723 assert(runtime_visible_annotations != NULL, "null visible annotations");
duke@0 724 cfs->skip_u1(runtime_visible_annotations_length, CHECK);
duke@0 725 } else if (PreserveAllAnnotations && attribute_name == vmSymbols::tag_runtime_invisible_annotations()) {
duke@0 726 runtime_invisible_annotations_length = attribute_length;
duke@0 727 runtime_invisible_annotations = cfs->get_u1_buffer();
duke@0 728 assert(runtime_invisible_annotations != NULL, "null invisible annotations");
duke@0 729 cfs->skip_u1(runtime_invisible_annotations_length, CHECK);
duke@0 730 } else {
duke@0 731 cfs->skip_u1(attribute_length, CHECK); // Skip unknown attributes
duke@0 732 }
duke@0 733 } else {
duke@0 734 cfs->skip_u1(attribute_length, CHECK); // Skip unknown attributes
duke@0 735 }
duke@0 736 }
duke@0 737
duke@0 738 *constantvalue_index_addr = constantvalue_index;
duke@0 739 *is_synthetic_addr = is_synthetic;
duke@0 740 *generic_signature_index_addr = generic_signature_index;
duke@0 741 *field_annotations = assemble_annotations(runtime_visible_annotations,
duke@0 742 runtime_visible_annotations_length,
duke@0 743 runtime_invisible_annotations,
duke@0 744 runtime_invisible_annotations_length,
duke@0 745 CHECK);
duke@0 746 return;
duke@0 747 }
duke@0 748
duke@0 749
duke@0 750 // Field allocation types. Used for computing field offsets.
duke@0 751
duke@0 752 enum FieldAllocationType {
duke@0 753 STATIC_OOP, // Oops
duke@0 754 STATIC_BYTE, // Boolean, Byte, char
duke@0 755 STATIC_SHORT, // shorts
duke@0 756 STATIC_WORD, // ints
duke@0 757 STATIC_DOUBLE, // long or double
duke@0 758 STATIC_ALIGNED_DOUBLE,// aligned long or double
duke@0 759 NONSTATIC_OOP,
duke@0 760 NONSTATIC_BYTE,
duke@0 761 NONSTATIC_SHORT,
duke@0 762 NONSTATIC_WORD,
duke@0 763 NONSTATIC_DOUBLE,
duke@0 764 NONSTATIC_ALIGNED_DOUBLE
duke@0 765 };
duke@0 766
duke@0 767
duke@0 768 struct FieldAllocationCount {
jcoomes@939 769 unsigned int static_oop_count;
jcoomes@939 770 unsigned int static_byte_count;
jcoomes@939 771 unsigned int static_short_count;
jcoomes@939 772 unsigned int static_word_count;
jcoomes@939 773 unsigned int static_double_count;
jcoomes@939 774 unsigned int nonstatic_oop_count;
jcoomes@939 775 unsigned int nonstatic_byte_count;
jcoomes@939 776 unsigned int nonstatic_short_count;
jcoomes@939 777 unsigned int nonstatic_word_count;
jcoomes@939 778 unsigned int nonstatic_double_count;
duke@0 779 };
duke@0 780
duke@0 781 typeArrayHandle ClassFileParser::parse_fields(constantPoolHandle cp, bool is_interface,
duke@0 782 struct FieldAllocationCount *fac,
duke@0 783 objArrayHandle* fields_annotations, TRAPS) {
duke@0 784 ClassFileStream* cfs = stream();
duke@0 785 typeArrayHandle nullHandle;
duke@0 786 cfs->guarantee_more(2, CHECK_(nullHandle)); // length
duke@0 787 u2 length = cfs->get_u2_fast();
duke@0 788 // Tuples of shorts [access, name index, sig index, initial value index, byte offset, generic signature index]
duke@0 789 typeArrayOop new_fields = oopFactory::new_permanent_shortArray(length*instanceKlass::next_offset, CHECK_(nullHandle));
duke@0 790 typeArrayHandle fields(THREAD, new_fields);
duke@0 791
duke@0 792 int index = 0;
duke@0 793 typeArrayHandle field_annotations;
duke@0 794 for (int n = 0; n < length; n++) {
duke@0 795 cfs->guarantee_more(8, CHECK_(nullHandle)); // access_flags, name_index, descriptor_index, attributes_count
duke@0 796
duke@0 797 AccessFlags access_flags;
duke@0 798 jint flags = cfs->get_u2_fast() & JVM_RECOGNIZED_FIELD_MODIFIERS;
duke@0 799 verify_legal_field_modifiers(flags, is_interface, CHECK_(nullHandle));
duke@0 800 access_flags.set_flags(flags);
duke@0 801
duke@0 802 u2 name_index = cfs->get_u2_fast();
duke@0 803 int cp_size = cp->length();
duke@0 804 check_property(
duke@0 805 valid_cp_range(name_index, cp_size) && cp->tag_at(name_index).is_utf8(),
duke@0 806 "Invalid constant pool index %u for field name in class file %s",
duke@0 807 name_index, CHECK_(nullHandle));
duke@0 808 symbolHandle name(THREAD, cp->symbol_at(name_index));
duke@0 809 verify_legal_field_name(name, CHECK_(nullHandle));
duke@0 810
duke@0 811 u2 signature_index = cfs->get_u2_fast();
duke@0 812 check_property(
duke@0 813 valid_cp_range(signature_index, cp_size) &&
duke@0 814 cp->tag_at(signature_index).is_utf8(),
duke@0 815 "Invalid constant pool index %u for field signature in class file %s",
duke@0 816 signature_index, CHECK_(nullHandle));
duke@0 817 symbolHandle sig(THREAD, cp->symbol_at(signature_index));
duke@0 818 verify_legal_field_signature(name, sig, CHECK_(nullHandle));
duke@0 819
duke@0 820 u2 constantvalue_index = 0;
duke@0 821 bool is_synthetic = false;
duke@0 822 u2 generic_signature_index = 0;
duke@0 823 bool is_static = access_flags.is_static();
duke@0 824
duke@0 825 u2 attributes_count = cfs->get_u2_fast();
duke@0 826 if (attributes_count > 0) {
duke@0 827 parse_field_attributes(cp, attributes_count, is_static, signature_index,
duke@0 828 &constantvalue_index, &is_synthetic,
duke@0 829 &generic_signature_index, &field_annotations,
duke@0 830 CHECK_(nullHandle));
duke@0 831 if (field_annotations.not_null()) {
duke@0 832 if (fields_annotations->is_null()) {
duke@0 833 objArrayOop md = oopFactory::new_system_objArray(length, CHECK_(nullHandle));
duke@0 834 *fields_annotations = objArrayHandle(THREAD, md);
duke@0 835 }
duke@0 836 (*fields_annotations)->obj_at_put(n, field_annotations());
duke@0 837 }
duke@0 838 if (is_synthetic) {
duke@0 839 access_flags.set_is_synthetic();
duke@0 840 }
duke@0 841 }
duke@0 842
duke@0 843 fields->short_at_put(index++, access_flags.as_short());
duke@0 844 fields->short_at_put(index++, name_index);
duke@0 845 fields->short_at_put(index++, signature_index);
duke@0 846 fields->short_at_put(index++, constantvalue_index);
duke@0 847
duke@0 848 // Remember how many oops we encountered and compute allocation type
duke@0 849 BasicType type = cp->basic_type_for_signature_at(signature_index);
duke@0 850 FieldAllocationType atype;
duke@0 851 if ( is_static ) {
duke@0 852 switch ( type ) {
duke@0 853 case T_BOOLEAN:
duke@0 854 case T_BYTE:
duke@0 855 fac->static_byte_count++;
duke@0 856 atype = STATIC_BYTE;
duke@0 857 break;
duke@0 858 case T_LONG:
duke@0 859 case T_DOUBLE:
duke@0 860 if (Universe::field_type_should_be_aligned(type)) {
duke@0 861 atype = STATIC_ALIGNED_DOUBLE;
duke@0 862 } else {
duke@0 863 atype = STATIC_DOUBLE;
duke@0 864 }
duke@0 865 fac->static_double_count++;
duke@0 866 break;
duke@0 867 case T_CHAR:
duke@0 868 case T_SHORT:
duke@0 869 fac->static_short_count++;
duke@0 870 atype = STATIC_SHORT;
duke@0 871 break;
duke@0 872 case T_FLOAT:
duke@0 873 case T_INT:
duke@0 874 fac->static_word_count++;
duke@0 875 atype = STATIC_WORD;
duke@0 876 break;
duke@0 877 case T_ARRAY:
duke@0 878 case T_OBJECT:
duke@0 879 fac->static_oop_count++;
duke@0 880 atype = STATIC_OOP;
duke@0 881 break;
duke@0 882 case T_ADDRESS:
duke@0 883 case T_VOID:
duke@0 884 default:
duke@0 885 assert(0, "bad field type");
duke@0 886 }
duke@0 887 } else {
duke@0 888 switch ( type ) {
duke@0 889 case T_BOOLEAN:
duke@0 890 case T_BYTE:
duke@0 891 fac->nonstatic_byte_count++;
duke@0 892 atype = NONSTATIC_BYTE;
duke@0 893 break;
duke@0 894 case T_LONG:
duke@0 895 case T_DOUBLE:
duke@0 896 if (Universe::field_type_should_be_aligned(type)) {
duke@0 897 atype = NONSTATIC_ALIGNED_DOUBLE;
duke@0 898 } else {
duke@0 899 atype = NONSTATIC_DOUBLE;
duke@0 900 }
duke@0 901 fac->nonstatic_double_count++;
duke@0 902 break;
duke@0 903 case T_CHAR:
duke@0 904 case T_SHORT:
duke@0 905 fac->nonstatic_short_count++;
duke@0 906 atype = NONSTATIC_SHORT;
duke@0 907 break;
duke@0 908 case T_FLOAT:
duke@0 909 case T_INT:
duke@0 910 fac->nonstatic_word_count++;
duke@0 911 atype = NONSTATIC_WORD;
duke@0 912 break;
duke@0 913 case T_ARRAY:
duke@0 914 case T_OBJECT:
duke@0 915 fac->nonstatic_oop_count++;
duke@0 916 atype = NONSTATIC_OOP;
duke@0 917 break;
duke@0 918 case T_ADDRESS:
duke@0 919 case T_VOID:
duke@0 920 default:
duke@0 921 assert(0, "bad field type");
duke@0 922 }
duke@0 923 }
duke@0 924
duke@0 925 // The correct offset is computed later (all oop fields will be located together)
duke@0 926 // We temporarily store the allocation type in the offset field
duke@0 927 fields->short_at_put(index++, atype);
duke@0 928 fields->short_at_put(index++, 0); // Clear out high word of byte offset
duke@0 929 fields->short_at_put(index++, generic_signature_index);
duke@0 930 }
duke@0 931
duke@0 932 if (_need_verify && length > 1) {
duke@0 933 // Check duplicated fields
duke@0 934 ResourceMark rm(THREAD);
duke@0 935 NameSigHash** names_and_sigs = NEW_RESOURCE_ARRAY_IN_THREAD(
duke@0 936 THREAD, NameSigHash*, HASH_ROW_SIZE);
duke@0 937 initialize_hashtable(names_and_sigs);
duke@0 938 bool dup = false;
duke@0 939 {
duke@0 940 debug_only(No_Safepoint_Verifier nsv;)
duke@0 941 for (int i = 0; i < length*instanceKlass::next_offset; i += instanceKlass::next_offset) {
duke@0 942 int name_index = fields->ushort_at(i + instanceKlass::name_index_offset);
duke@0 943 symbolOop name = cp->symbol_at(name_index);
duke@0 944 int sig_index = fields->ushort_at(i + instanceKlass::signature_index_offset);
duke@0 945 symbolOop sig = cp->symbol_at(sig_index);
duke@0 946 // If no duplicates, add name/signature in hashtable names_and_sigs.
duke@0 947 if (!put_after_lookup(name, sig, names_and_sigs)) {
duke@0 948 dup = true;
duke@0 949 break;
duke@0 950 }
duke@0 951 }
duke@0 952 }
duke@0 953 if (dup) {
duke@0 954 classfile_parse_error("Duplicate field name&signature in class file %s",
duke@0 955 CHECK_(nullHandle));
duke@0 956 }
duke@0 957 }
duke@0 958
duke@0 959 return fields;
duke@0 960 }
duke@0 961
duke@0 962
duke@0 963 static void copy_u2_with_conversion(u2* dest, u2* src, int length) {
duke@0 964 while (length-- > 0) {
duke@0 965 *dest++ = Bytes::get_Java_u2((u1*) (src++));
duke@0 966 }
duke@0 967 }
duke@0 968
duke@0 969
duke@0 970 typeArrayHandle ClassFileParser::parse_exception_table(u4 code_length,
duke@0 971 u4 exception_table_length,
duke@0 972 constantPoolHandle cp,
duke@0 973 TRAPS) {
duke@0 974 ClassFileStream* cfs = stream();
duke@0 975 typeArrayHandle nullHandle;
duke@0 976
duke@0 977 // 4-tuples of ints [start_pc, end_pc, handler_pc, catch_type index]
duke@0 978 typeArrayOop eh = oopFactory::new_permanent_intArray(exception_table_length*4, CHECK_(nullHandle));
duke@0 979 typeArrayHandle exception_handlers = typeArrayHandle(THREAD, eh);
duke@0 980
duke@0 981 int index = 0;
duke@0 982 cfs->guarantee_more(8 * exception_table_length, CHECK_(nullHandle)); // start_pc, end_pc, handler_pc, catch_type_index
duke@0 983 for (unsigned int i = 0; i < exception_table_length; i++) {
duke@0 984 u2 start_pc = cfs->get_u2_fast();
duke@0 985 u2 end_pc = cfs->get_u2_fast();
duke@0 986 u2 handler_pc = cfs->get_u2_fast();
duke@0 987 u2 catch_type_index = cfs->get_u2_fast();
duke@0 988 // Will check legal target after parsing code array in verifier.
duke@0 989 if (_need_verify) {
duke@0 990 guarantee_property((start_pc < end_pc) && (end_pc <= code_length),
duke@0 991 "Illegal exception table range in class file %s", CHECK_(nullHandle));
duke@0 992 guarantee_property(handler_pc < code_length,
duke@0 993 "Illegal exception table handler in class file %s", CHECK_(nullHandle));
duke@0 994 if (catch_type_index != 0) {
duke@0 995 guarantee_property(valid_cp_range(catch_type_index, cp->length()) &&
jrose@431 996 is_klass_reference(cp, catch_type_index),
duke@0 997 "Catch type in exception table has bad constant type in class file %s", CHECK_(nullHandle));
duke@0 998 }
duke@0 999 }
duke@0 1000 exception_handlers->int_at_put(index++, start_pc);
duke@0 1001 exception_handlers->int_at_put(index++, end_pc);
duke@0 1002 exception_handlers->int_at_put(index++, handler_pc);
duke@0 1003 exception_handlers->int_at_put(index++, catch_type_index);
duke@0 1004 }
duke@0 1005 return exception_handlers;
duke@0 1006 }
duke@0 1007
duke@0 1008 void ClassFileParser::parse_linenumber_table(
duke@0 1009 u4 code_attribute_length, u4 code_length,
duke@0 1010 CompressedLineNumberWriteStream** write_stream, TRAPS) {
duke@0 1011 ClassFileStream* cfs = stream();
duke@0 1012 unsigned int num_entries = cfs->get_u2(CHECK);
duke@0 1013
duke@0 1014 // Each entry is a u2 start_pc, and a u2 line_number
duke@0 1015 unsigned int length_in_bytes = num_entries * (sizeof(u2) + sizeof(u2));
duke@0 1016
duke@0 1017 // Verify line number attribute and table length
duke@0 1018 check_property(
duke@0 1019 code_attribute_length == sizeof(u2) + length_in_bytes,
duke@0 1020 "LineNumberTable attribute has wrong length in class file %s", CHECK);
duke@0 1021
duke@0 1022 cfs->guarantee_more(length_in_bytes, CHECK);
duke@0 1023
duke@0 1024 if ((*write_stream) == NULL) {
duke@0 1025 if (length_in_bytes > fixed_buffer_size) {
duke@0 1026 (*write_stream) = new CompressedLineNumberWriteStream(length_in_bytes);
duke@0 1027 } else {
duke@0 1028 (*write_stream) = new CompressedLineNumberWriteStream(
duke@0 1029 linenumbertable_buffer, fixed_buffer_size);
duke@0 1030 }
duke@0 1031 }
duke@0 1032
duke@0 1033 while (num_entries-- > 0) {
duke@0 1034 u2 bci = cfs->get_u2_fast(); // start_pc
duke@0 1035 u2 line = cfs->get_u2_fast(); // line_number
duke@0 1036 guarantee_property(bci < code_length,
duke@0 1037 "Invalid pc in LineNumberTable in class file %s", CHECK);
duke@0 1038 (*write_stream)->write_pair(bci, line);
duke@0 1039 }
duke@0 1040 }
duke@0 1041
duke@0 1042
duke@0 1043 // Class file LocalVariableTable elements.
duke@0 1044 class Classfile_LVT_Element VALUE_OBJ_CLASS_SPEC {
duke@0 1045 public:
duke@0 1046 u2 start_bci;
duke@0 1047 u2 length;
duke@0 1048 u2 name_cp_index;
duke@0 1049 u2 descriptor_cp_index;
duke@0 1050 u2 slot;
duke@0 1051 };
duke@0 1052
duke@0 1053
duke@0 1054 class LVT_Hash: public CHeapObj {
duke@0 1055 public:
duke@0 1056 LocalVariableTableElement *_elem; // element
duke@0 1057 LVT_Hash* _next; // Next entry in hash table
duke@0 1058 };
duke@0 1059
duke@0 1060 unsigned int hash(LocalVariableTableElement *elem) {
duke@0 1061 unsigned int raw_hash = elem->start_bci;
duke@0 1062
duke@0 1063 raw_hash = elem->length + raw_hash * 37;
duke@0 1064 raw_hash = elem->name_cp_index + raw_hash * 37;
duke@0 1065 raw_hash = elem->slot + raw_hash * 37;
duke@0 1066
duke@0 1067 return raw_hash % HASH_ROW_SIZE;
duke@0 1068 }
duke@0 1069
duke@0 1070 void initialize_hashtable(LVT_Hash** table) {
duke@0 1071 for (int i = 0; i < HASH_ROW_SIZE; i++) {
duke@0 1072 table[i] = NULL;
duke@0 1073 }
duke@0 1074 }
duke@0 1075
duke@0 1076 void clear_hashtable(LVT_Hash** table) {
duke@0 1077 for (int i = 0; i < HASH_ROW_SIZE; i++) {
duke@0 1078 LVT_Hash* current = table[i];
duke@0 1079 LVT_Hash* next;
duke@0 1080 while (current != NULL) {
duke@0 1081 next = current->_next;
duke@0 1082 current->_next = NULL;
duke@0 1083 delete(current);
duke@0 1084 current = next;
duke@0 1085 }
duke@0 1086 table[i] = NULL;
duke@0 1087 }
duke@0 1088 }
duke@0 1089
duke@0 1090 LVT_Hash* LVT_lookup(LocalVariableTableElement *elem, int index, LVT_Hash** table) {
duke@0 1091 LVT_Hash* entry = table[index];
duke@0 1092
duke@0 1093 /*
duke@0 1094 * 3-tuple start_bci/length/slot has to be unique key,
duke@0 1095 * so the following comparison seems to be redundant:
duke@0 1096 * && elem->name_cp_index == entry->_elem->name_cp_index
duke@0 1097 */
duke@0 1098 while (entry != NULL) {
duke@0 1099 if (elem->start_bci == entry->_elem->start_bci
duke@0 1100 && elem->length == entry->_elem->length
duke@0 1101 && elem->name_cp_index == entry->_elem->name_cp_index
duke@0 1102 && elem->slot == entry->_elem->slot
duke@0 1103 ) {
duke@0 1104 return entry;
duke@0 1105 }
duke@0 1106 entry = entry->_next;
duke@0 1107 }
duke@0 1108 return NULL;
duke@0 1109 }
duke@0 1110
duke@0 1111 // Return false if the local variable is found in table.
duke@0 1112 // Return true if no duplicate is found.
duke@0 1113 // And local variable is added as a new entry in table.
duke@0 1114 bool LVT_put_after_lookup(LocalVariableTableElement *elem, LVT_Hash** table) {
duke@0 1115 // First lookup for duplicates
duke@0 1116 int index = hash(elem);
duke@0 1117 LVT_Hash* entry = LVT_lookup(elem, index, table);
duke@0 1118
duke@0 1119 if (entry != NULL) {
duke@0 1120 return false;
duke@0 1121 }
duke@0 1122 // No duplicate is found, allocate a new entry and fill it.
duke@0 1123 if ((entry = new LVT_Hash()) == NULL) {
duke@0 1124 return false;
duke@0 1125 }
duke@0 1126 entry->_elem = elem;
duke@0 1127
duke@0 1128 // Insert into hash table
duke@0 1129 entry->_next = table[index];
duke@0 1130 table[index] = entry;
duke@0 1131
duke@0 1132 return true;
duke@0 1133 }
duke@0 1134
duke@0 1135 void copy_lvt_element(Classfile_LVT_Element *src, LocalVariableTableElement *lvt) {
duke@0 1136 lvt->start_bci = Bytes::get_Java_u2((u1*) &src->start_bci);
duke@0 1137 lvt->length = Bytes::get_Java_u2((u1*) &src->length);
duke@0 1138 lvt->name_cp_index = Bytes::get_Java_u2((u1*) &src->name_cp_index);
duke@0 1139 lvt->descriptor_cp_index = Bytes::get_Java_u2((u1*) &src->descriptor_cp_index);
duke@0 1140 lvt->signature_cp_index = 0;
duke@0 1141 lvt->slot = Bytes::get_Java_u2((u1*) &src->slot);
duke@0 1142 }
duke@0 1143
duke@0 1144 // Function is used to parse both attributes:
duke@0 1145 // LocalVariableTable (LVT) and LocalVariableTypeTable (LVTT)
duke@0 1146 u2* ClassFileParser::parse_localvariable_table(u4 code_length,
duke@0 1147 u2 max_locals,
duke@0 1148 u4 code_attribute_length,
duke@0 1149 constantPoolHandle cp,
duke@0 1150 u2* localvariable_table_length,
duke@0 1151 bool isLVTT,
duke@0 1152 TRAPS) {
duke@0 1153 ClassFileStream* cfs = stream();
duke@0 1154 const char * tbl_name = (isLVTT) ? "LocalVariableTypeTable" : "LocalVariableTable";
duke@0 1155 *localvariable_table_length = cfs->get_u2(CHECK_NULL);
duke@0 1156 unsigned int size = (*localvariable_table_length) * sizeof(Classfile_LVT_Element) / sizeof(u2);
duke@0 1157 // Verify local variable table attribute has right length
duke@0 1158 if (_need_verify) {
duke@0 1159 guarantee_property(code_attribute_length == (sizeof(*localvariable_table_length) + size * sizeof(u2)),
duke@0 1160 "%s has wrong length in class file %s", tbl_name, CHECK_NULL);
duke@0 1161 }
duke@0 1162 u2* localvariable_table_start = cfs->get_u2_buffer();
duke@0 1163 assert(localvariable_table_start != NULL, "null local variable table");
duke@0 1164 if (!_need_verify) {
duke@0 1165 cfs->skip_u2_fast(size);
duke@0 1166 } else {
duke@0 1167 cfs->guarantee_more(size * 2, CHECK_NULL);
duke@0 1168 for(int i = 0; i < (*localvariable_table_length); i++) {
duke@0 1169 u2 start_pc = cfs->get_u2_fast();
duke@0 1170 u2 length = cfs->get_u2_fast();
duke@0 1171 u2 name_index = cfs->get_u2_fast();
duke@0 1172 u2 descriptor_index = cfs->get_u2_fast();
duke@0 1173 u2 index = cfs->get_u2_fast();
duke@0 1174 // Assign to a u4 to avoid overflow
duke@0 1175 u4 end_pc = (u4)start_pc + (u4)length;
duke@0 1176
duke@0 1177 if (start_pc >= code_length) {
duke@0 1178 classfile_parse_error(
duke@0 1179 "Invalid start_pc %u in %s in class file %s",
duke@0 1180 start_pc, tbl_name, CHECK_NULL);
duke@0 1181 }
duke@0 1182 if (end_pc > code_length) {
duke@0 1183 classfile_parse_error(
duke@0 1184 "Invalid length %u in %s in class file %s",
duke@0 1185 length, tbl_name, CHECK_NULL);
duke@0 1186 }
duke@0 1187 int cp_size = cp->length();
duke@0 1188 guarantee_property(
duke@0 1189 valid_cp_range(name_index, cp_size) &&
duke@0 1190 cp->tag_at(name_index).is_utf8(),
duke@0 1191 "Name index %u in %s has bad constant type in class file %s",
duke@0 1192 name_index, tbl_name, CHECK_NULL);
duke@0 1193 guarantee_property(
duke@0 1194 valid_cp_range(descriptor_index, cp_size) &&
duke@0 1195 cp->tag_at(descriptor_index).is_utf8(),
duke@0 1196 "Signature index %u in %s has bad constant type in class file %s",
duke@0 1197 descriptor_index, tbl_name, CHECK_NULL);
duke@0 1198
duke@0 1199 symbolHandle name(THREAD, cp->symbol_at(name_index));
duke@0 1200 symbolHandle sig(THREAD, cp->symbol_at(descriptor_index));
duke@0 1201 verify_legal_field_name(name, CHECK_NULL);
duke@0 1202 u2 extra_slot = 0;
duke@0 1203 if (!isLVTT) {
duke@0 1204 verify_legal_field_signature(name, sig, CHECK_NULL);
duke@0 1205
duke@0 1206 // 4894874: check special cases for double and long local variables
duke@0 1207 if (sig() == vmSymbols::type_signature(T_DOUBLE) ||
duke@0 1208 sig() == vmSymbols::type_signature(T_LONG)) {
duke@0 1209 extra_slot = 1;
duke@0 1210 }
duke@0 1211 }
duke@0 1212 guarantee_property((index + extra_slot) < max_locals,
duke@0 1213 "Invalid index %u in %s in class file %s",
duke@0 1214 index, tbl_name, CHECK_NULL);
duke@0 1215 }
duke@0 1216 }
duke@0 1217 return localvariable_table_start;
duke@0 1218 }
duke@0 1219
duke@0 1220
duke@0 1221 void ClassFileParser::parse_type_array(u2 array_length, u4 code_length, u4* u1_index, u4* u2_index,
duke@0 1222 u1* u1_array, u2* u2_array, constantPoolHandle cp, TRAPS) {
duke@0 1223 ClassFileStream* cfs = stream();
duke@0 1224 u2 index = 0; // index in the array with long/double occupying two slots
duke@0 1225 u4 i1 = *u1_index;
duke@0 1226 u4 i2 = *u2_index + 1;
duke@0 1227 for(int i = 0; i < array_length; i++) {
duke@0 1228 u1 tag = u1_array[i1++] = cfs->get_u1(CHECK);
duke@0 1229 index++;
duke@0 1230 if (tag == ITEM_Long || tag == ITEM_Double) {
duke@0 1231 index++;
duke@0 1232 } else if (tag == ITEM_Object) {
duke@0 1233 u2 class_index = u2_array[i2++] = cfs->get_u2(CHECK);
duke@0 1234 guarantee_property(valid_cp_range(class_index, cp->length()) &&
jrose@431 1235 is_klass_reference(cp, class_index),
duke@0 1236 "Bad class index %u in StackMap in class file %s",
duke@0 1237 class_index, CHECK);
duke@0 1238 } else if (tag == ITEM_Uninitialized) {
duke@0 1239 u2 offset = u2_array[i2++] = cfs->get_u2(CHECK);
duke@0 1240 guarantee_property(
duke@0 1241 offset < code_length,
duke@0 1242 "Bad uninitialized type offset %u in StackMap in class file %s",
duke@0 1243 offset, CHECK);
duke@0 1244 } else {
duke@0 1245 guarantee_property(
duke@0 1246 tag <= (u1)ITEM_Uninitialized,
duke@0 1247 "Unknown variable type %u in StackMap in class file %s",
duke@0 1248 tag, CHECK);
duke@0 1249 }
duke@0 1250 }
duke@0 1251 u2_array[*u2_index] = index;
duke@0 1252 *u1_index = i1;
duke@0 1253 *u2_index = i2;
duke@0 1254 }
duke@0 1255
duke@0 1256 typeArrayOop ClassFileParser::parse_stackmap_table(
duke@0 1257 u4 code_attribute_length, TRAPS) {
duke@0 1258 if (code_attribute_length == 0)
duke@0 1259 return NULL;
duke@0 1260
duke@0 1261 ClassFileStream* cfs = stream();
duke@0 1262 u1* stackmap_table_start = cfs->get_u1_buffer();
duke@0 1263 assert(stackmap_table_start != NULL, "null stackmap table");
duke@0 1264
duke@0 1265 // check code_attribute_length first
duke@0 1266 stream()->skip_u1(code_attribute_length, CHECK_NULL);
duke@0 1267
duke@0 1268 if (!_need_verify && !DumpSharedSpaces) {
duke@0 1269 return NULL;
duke@0 1270 }
duke@0 1271
duke@0 1272 typeArrayOop stackmap_data =
duke@0 1273 oopFactory::new_permanent_byteArray(code_attribute_length, CHECK_NULL);
duke@0 1274
duke@0 1275 stackmap_data->set_length(code_attribute_length);
duke@0 1276 memcpy((void*)stackmap_data->byte_at_addr(0),
duke@0 1277 (void*)stackmap_table_start, code_attribute_length);
duke@0 1278 return stackmap_data;
duke@0 1279 }
duke@0 1280
duke@0 1281 u2* ClassFileParser::parse_checked_exceptions(u2* checked_exceptions_length,
duke@0 1282 u4 method_attribute_length,
duke@0 1283 constantPoolHandle cp, TRAPS) {
duke@0 1284 ClassFileStream* cfs = stream();
duke@0 1285 cfs->guarantee_more(2, CHECK_NULL); // checked_exceptions_length
duke@0 1286 *checked_exceptions_length = cfs->get_u2_fast();
duke@0 1287 unsigned int size = (*checked_exceptions_length) * sizeof(CheckedExceptionElement) / sizeof(u2);
duke@0 1288 u2* checked_exceptions_start = cfs->get_u2_buffer();
duke@0 1289 assert(checked_exceptions_start != NULL, "null checked exceptions");
duke@0 1290 if (!_need_verify) {
duke@0 1291 cfs->skip_u2_fast(size);
duke@0 1292 } else {
duke@0 1293 // Verify each value in the checked exception table
duke@0 1294 u2 checked_exception;
duke@0 1295 u2 len = *checked_exceptions_length;
duke@0 1296 cfs->guarantee_more(2 * len, CHECK_NULL);
duke@0 1297 for (int i = 0; i < len; i++) {
duke@0 1298 checked_exception = cfs->get_u2_fast();
duke@0 1299 check_property(
duke@0 1300 valid_cp_range(checked_exception, cp->length()) &&
jrose@431 1301 is_klass_reference(cp, checked_exception),
duke@0 1302 "Exception name has bad type at constant pool %u in class file %s",
duke@0 1303 checked_exception, CHECK_NULL);
duke@0 1304 }
duke@0 1305 }
duke@0 1306 // check exceptions attribute length
duke@0 1307 if (_need_verify) {
duke@0 1308 guarantee_property(method_attribute_length == (sizeof(*checked_exceptions_length) +
duke@0 1309 sizeof(u2) * size),
duke@0 1310 "Exceptions attribute has wrong length in class file %s", CHECK_NULL);
duke@0 1311 }
duke@0 1312 return checked_exceptions_start;
duke@0 1313 }
duke@0 1314
duke@0 1315
duke@0 1316 #define MAX_ARGS_SIZE 255
duke@0 1317 #define MAX_CODE_SIZE 65535
duke@0 1318 #define INITIAL_MAX_LVT_NUMBER 256
duke@0 1319
duke@0 1320 // Note: the parse_method below is big and clunky because all parsing of the code and exceptions
duke@0 1321 // attribute is inlined. This is curbersome to avoid since we inline most of the parts in the
duke@0 1322 // methodOop to save footprint, so we only know the size of the resulting methodOop when the
duke@0 1323 // entire method attribute is parsed.
duke@0 1324 //
duke@0 1325 // The promoted_flags parameter is used to pass relevant access_flags
duke@0 1326 // from the method back up to the containing klass. These flag values
duke@0 1327 // are added to klass's access_flags.
duke@0 1328
duke@0 1329 methodHandle ClassFileParser::parse_method(constantPoolHandle cp, bool is_interface,
duke@0 1330 AccessFlags *promoted_flags,
duke@0 1331 typeArrayHandle* method_annotations,
duke@0 1332 typeArrayHandle* method_parameter_annotations,
duke@0 1333 typeArrayHandle* method_default_annotations,
duke@0 1334 TRAPS) {
duke@0 1335 ClassFileStream* cfs = stream();
duke@0 1336 methodHandle nullHandle;
duke@0 1337 ResourceMark rm(THREAD);
duke@0 1338 // Parse fixed parts
duke@0 1339 cfs->guarantee_more(8, CHECK_(nullHandle)); // access_flags, name_index, descriptor_index, attributes_count
duke@0 1340
duke@0 1341 int flags = cfs->get_u2_fast();
duke@0 1342 u2 name_index = cfs->get_u2_fast();
duke@0 1343 int cp_size = cp->length();
duke@0 1344 check_property(
duke@0 1345 valid_cp_range(name_index, cp_size) &&
duke@0 1346 cp->tag_at(name_index).is_utf8(),
duke@0 1347 "Illegal constant pool index %u for method name in class file %s",
duke@0 1348 name_index, CHECK_(nullHandle));
duke@0 1349 symbolHandle name(THREAD, cp->symbol_at(name_index));
duke@0 1350 verify_legal_method_name(name, CHECK_(nullHandle));
duke@0 1351
duke@0 1352 u2 signature_index = cfs->get_u2_fast();
duke@0 1353 guarantee_property(
duke@0 1354 valid_cp_range(signature_index, cp_size) &&
duke@0 1355 cp->tag_at(signature_index).is_utf8(),
duke@0 1356 "Illegal constant pool index %u for method signature in class file %s",
duke@0 1357 signature_index, CHECK_(nullHandle));
duke@0 1358 symbolHandle signature(THREAD, cp->symbol_at(signature_index));
duke@0 1359
duke@0 1360 AccessFlags access_flags;
duke@0 1361 if (name == vmSymbols::class_initializer_name()) {
duke@0 1362 // We ignore the access flags for a class initializer. (JVM Spec. p. 116)
duke@0 1363 flags = JVM_ACC_STATIC;
duke@0 1364 } else {
duke@0 1365 verify_legal_method_modifiers(flags, is_interface, name, CHECK_(nullHandle));
duke@0 1366 }
duke@0 1367
duke@0 1368 int args_size = -1; // only used when _need_verify is true
duke@0 1369 if (_need_verify) {
duke@0 1370 args_size = ((flags & JVM_ACC_STATIC) ? 0 : 1) +
duke@0 1371 verify_legal_method_signature(name, signature, CHECK_(nullHandle));
duke@0 1372 if (args_size > MAX_ARGS_SIZE) {
duke@0 1373 classfile_parse_error("Too many arguments in method signature in class file %s", CHECK_(nullHandle));
duke@0 1374 }
duke@0 1375 }
duke@0 1376
duke@0 1377 access_flags.set_flags(flags & JVM_RECOGNIZED_METHOD_MODIFIERS);
duke@0 1378
duke@0 1379 // Default values for code and exceptions attribute elements
duke@0 1380 u2 max_stack = 0;
duke@0 1381 u2 max_locals = 0;
duke@0 1382 u4 code_length = 0;
duke@0 1383 u1* code_start = 0;
duke@0 1384 u2 exception_table_length = 0;
duke@0 1385 typeArrayHandle exception_handlers(THREAD, Universe::the_empty_int_array());
duke@0 1386 u2 checked_exceptions_length = 0;
duke@0 1387 u2* checked_exceptions_start = NULL;
duke@0 1388 CompressedLineNumberWriteStream* linenumber_table = NULL;
duke@0 1389 int linenumber_table_length = 0;
duke@0 1390 int total_lvt_length = 0;
duke@0 1391 u2 lvt_cnt = 0;
duke@0 1392 u2 lvtt_cnt = 0;
duke@0 1393 bool lvt_allocated = false;
duke@0 1394 u2 max_lvt_cnt = INITIAL_MAX_LVT_NUMBER;
duke@0 1395 u2 max_lvtt_cnt = INITIAL_MAX_LVT_NUMBER;
duke@0 1396 u2* localvariable_table_length;
duke@0 1397 u2** localvariable_table_start;
duke@0 1398 u2* localvariable_type_table_length;
duke@0 1399 u2** localvariable_type_table_start;
duke@0 1400 bool parsed_code_attribute = false;
duke@0 1401 bool parsed_checked_exceptions_attribute = false;
duke@0 1402 bool parsed_stackmap_attribute = false;
duke@0 1403 // stackmap attribute - JDK1.5
duke@0 1404 typeArrayHandle stackmap_data;
duke@0 1405 u2 generic_signature_index = 0;
duke@0 1406 u1* runtime_visible_annotations = NULL;
duke@0 1407 int runtime_visible_annotations_length = 0;
duke@0 1408 u1* runtime_invisible_annotations = NULL;
duke@0 1409 int runtime_invisible_annotations_length = 0;
duke@0 1410 u1* runtime_visible_parameter_annotations = NULL;
duke@0 1411 int runtime_visible_parameter_annotations_length = 0;
duke@0 1412 u1* runtime_invisible_parameter_annotations = NULL;
duke@0 1413 int runtime_invisible_parameter_annotations_length = 0;
duke@0 1414 u1* annotation_default = NULL;
duke@0 1415 int annotation_default_length = 0;
duke@0 1416
duke@0 1417 // Parse code and exceptions attribute
duke@0 1418 u2 method_attributes_count = cfs->get_u2_fast();
duke@0 1419 while (method_attributes_count--) {
duke@0 1420 cfs->guarantee_more(6, CHECK_(nullHandle)); // method_attribute_name_index, method_attribute_length
duke@0 1421 u2 method_attribute_name_index = cfs->get_u2_fast();
duke@0 1422 u4 method_attribute_length = cfs->get_u4_fast();
duke@0 1423 check_property(
duke@0 1424 valid_cp_range(method_attribute_name_index, cp_size) &&
duke@0 1425 cp->tag_at(method_attribute_name_index).is_utf8(),
duke@0 1426 "Invalid method attribute name index %u in class file %s",
duke@0 1427 method_attribute_name_index, CHECK_(nullHandle));
duke@0 1428
duke@0 1429 symbolOop method_attribute_name = cp->symbol_at(method_attribute_name_index);
duke@0 1430 if (method_attribute_name == vmSymbols::tag_code()) {
duke@0 1431 // Parse Code attribute
duke@0 1432 if (_need_verify) {
duke@0 1433 guarantee_property(!access_flags.is_native() && !access_flags.is_abstract(),
duke@0 1434 "Code attribute in native or abstract methods in class file %s",
duke@0 1435 CHECK_(nullHandle));
duke@0 1436 }
duke@0 1437 if (parsed_code_attribute) {
duke@0 1438 classfile_parse_error("Multiple Code attributes in class file %s", CHECK_(nullHandle));
duke@0 1439 }
duke@0 1440 parsed_code_attribute = true;
duke@0 1441
duke@0 1442 // Stack size, locals size, and code size
duke@0 1443 if (_major_version == 45 && _minor_version <= 2) {
duke@0 1444 cfs->guarantee_more(4, CHECK_(nullHandle));
duke@0 1445 max_stack = cfs->get_u1_fast();
duke@0 1446 max_locals = cfs->get_u1_fast();
duke@0 1447 code_length = cfs->get_u2_fast();
duke@0 1448 } else {
duke@0 1449 cfs->guarantee_more(8, CHECK_(nullHandle));
duke@0 1450 max_stack = cfs->get_u2_fast();
duke@0 1451 max_locals = cfs->get_u2_fast();
duke@0 1452 code_length = cfs->get_u4_fast();
duke@0 1453 }
duke@0 1454 if (_need_verify) {
duke@0 1455 guarantee_property(args_size <= max_locals,
duke@0 1456 "Arguments can't fit into locals in class file %s", CHECK_(nullHandle));
duke@0 1457 guarantee_property(code_length > 0 && code_length <= MAX_CODE_SIZE,
duke@0 1458 "Invalid method Code length %u in class file %s",
duke@0 1459 code_length, CHECK_(nullHandle));
duke@0 1460 }
duke@0 1461 // Code pointer
duke@0 1462 code_start = cfs->get_u1_buffer();
duke@0 1463 assert(code_start != NULL, "null code start");
duke@0 1464 cfs->guarantee_more(code_length, CHECK_(nullHandle));
duke@0 1465 cfs->skip_u1_fast(code_length);
duke@0 1466
duke@0 1467 // Exception handler table
duke@0 1468 cfs->guarantee_more(2, CHECK_(nullHandle)); // exception_table_length
duke@0 1469 exception_table_length = cfs->get_u2_fast();
duke@0 1470 if (exception_table_length > 0) {
duke@0 1471 exception_handlers =
duke@0 1472 parse_exception_table(code_length, exception_table_length, cp, CHECK_(nullHandle));
duke@0 1473 }
duke@0 1474
duke@0 1475 // Parse additional attributes in code attribute
duke@0 1476 cfs->guarantee_more(2, CHECK_(nullHandle)); // code_attributes_count
duke@0 1477 u2 code_attributes_count = cfs->get_u2_fast();
kamg@92 1478
kamg@92 1479 unsigned int calculated_attribute_length = 0;
kamg@92 1480
kamg@92 1481 if (_major_version > 45 || (_major_version == 45 && _minor_version > 2)) {
kamg@92 1482 calculated_attribute_length =
kamg@92 1483 sizeof(max_stack) + sizeof(max_locals) + sizeof(code_length);
kamg@92 1484 } else {
kamg@92 1485 // max_stack, locals and length are smaller in pre-version 45.2 classes
kamg@92 1486 calculated_attribute_length = sizeof(u1) + sizeof(u1) + sizeof(u2);
kamg@92 1487 }
kamg@92 1488 calculated_attribute_length +=
kamg@92 1489 code_length +
kamg@92 1490 sizeof(exception_table_length) +
kamg@92 1491 sizeof(code_attributes_count) +
kamg@92 1492 exception_table_length *
kamg@92 1493 ( sizeof(u2) + // start_pc
kamg@92 1494 sizeof(u2) + // end_pc
kamg@92 1495 sizeof(u2) + // handler_pc
kamg@92 1496 sizeof(u2) ); // catch_type_index
duke@0 1497
duke@0 1498 while (code_attributes_count--) {
duke@0 1499 cfs->guarantee_more(6, CHECK_(nullHandle)); // code_attribute_name_index, code_attribute_length
duke@0 1500 u2 code_attribute_name_index = cfs->get_u2_fast();
duke@0 1501 u4 code_attribute_length = cfs->get_u4_fast();
duke@0 1502 calculated_attribute_length += code_attribute_length +
duke@0 1503 sizeof(code_attribute_name_index) +
duke@0 1504 sizeof(code_attribute_length);
duke@0 1505 check_property(valid_cp_range(code_attribute_name_index, cp_size) &&
duke@0 1506 cp->tag_at(code_attribute_name_index).is_utf8(),
duke@0 1507 "Invalid code attribute name index %u in class file %s",
duke@0 1508 code_attribute_name_index,
duke@0 1509 CHECK_(nullHandle));
duke@0 1510 if (LoadLineNumberTables &&
duke@0 1511 cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_line_number_table()) {
duke@0 1512 // Parse and compress line number table
duke@0 1513 parse_linenumber_table(code_attribute_length, code_length,
duke@0 1514 &linenumber_table, CHECK_(nullHandle));
duke@0 1515
duke@0 1516 } else if (LoadLocalVariableTables &&
duke@0 1517 cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_local_variable_table()) {
duke@0 1518 // Parse local variable table
duke@0 1519 if (!lvt_allocated) {
duke@0 1520 localvariable_table_length = NEW_RESOURCE_ARRAY_IN_THREAD(
duke@0 1521 THREAD, u2, INITIAL_MAX_LVT_NUMBER);
duke@0 1522 localvariable_table_start = NEW_RESOURCE_ARRAY_IN_THREAD(
duke@0 1523 THREAD, u2*, INITIAL_MAX_LVT_NUMBER);
duke@0 1524 localvariable_type_table_length = NEW_RESOURCE_ARRAY_IN_THREAD(
duke@0 1525 THREAD, u2, INITIAL_MAX_LVT_NUMBER);
duke@0 1526 localvariable_type_table_start = NEW_RESOURCE_ARRAY_IN_THREAD(
duke@0 1527 THREAD, u2*, INITIAL_MAX_LVT_NUMBER);
duke@0 1528 lvt_allocated = true;
duke@0 1529 }
duke@0 1530 if (lvt_cnt == max_lvt_cnt) {
duke@0 1531 max_lvt_cnt <<= 1;
duke@0 1532 REALLOC_RESOURCE_ARRAY(u2, localvariable_table_length, lvt_cnt, max_lvt_cnt);
duke@0 1533 REALLOC_RESOURCE_ARRAY(u2*, localvariable_table_start, lvt_cnt, max_lvt_cnt);
duke@0 1534 }
duke@0 1535 localvariable_table_start[lvt_cnt] =
duke@0 1536 parse_localvariable_table(code_length,
duke@0 1537 max_locals,
duke@0 1538 code_attribute_length,
duke@0 1539 cp,
duke@0 1540 &localvariable_table_length[lvt_cnt],
duke@0 1541 false, // is not LVTT
duke@0 1542 CHECK_(nullHandle));
duke@0 1543 total_lvt_length += localvariable_table_length[lvt_cnt];
duke@0 1544 lvt_cnt++;
duke@0 1545 } else if (LoadLocalVariableTypeTables &&
duke@0 1546 _major_version >= JAVA_1_5_VERSION &&
duke@0 1547 cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_local_variable_type_table()) {
duke@0 1548 if (!lvt_allocated) {
duke@0 1549 localvariable_table_length = NEW_RESOURCE_ARRAY_IN_THREAD(
duke@0 1550 THREAD, u2, INITIAL_MAX_LVT_NUMBER);
duke@0 1551 localvariable_table_start = NEW_RESOURCE_ARRAY_IN_THREAD(
duke@0 1552 THREAD, u2*, INITIAL_MAX_LVT_NUMBER);
duke@0 1553 localvariable_type_table_length = NEW_RESOURCE_ARRAY_IN_THREAD(
duke@0 1554 THREAD, u2, INITIAL_MAX_LVT_NUMBER);
duke@0 1555 localvariable_type_table_start = NEW_RESOURCE_ARRAY_IN_THREAD(
duke@0 1556 THREAD, u2*, INITIAL_MAX_LVT_NUMBER);
duke@0 1557 lvt_allocated = true;
duke@0 1558 }
duke@0 1559 // Parse local variable type table
duke@0 1560 if (lvtt_cnt == max_lvtt_cnt) {
duke@0 1561 max_lvtt_cnt <<= 1;
duke@0 1562 REALLOC_RESOURCE_ARRAY(u2, localvariable_type_table_length, lvtt_cnt, max_lvtt_cnt);
duke@0 1563 REALLOC_RESOURCE_ARRAY(u2*, localvariable_type_table_start, lvtt_cnt, max_lvtt_cnt);
duke@0 1564 }
duke@0 1565 localvariable_type_table_start[lvtt_cnt] =
duke@0 1566 parse_localvariable_table(code_length,
duke@0 1567 max_locals,
duke@0 1568 code_attribute_length,
duke@0 1569 cp,
duke@0 1570 &localvariable_type_table_length[lvtt_cnt],
duke@0 1571 true, // is LVTT
duke@0 1572 CHECK_(nullHandle));
duke@0 1573 lvtt_cnt++;
duke@0 1574 } else if (UseSplitVerifier &&
duke@0 1575 _major_version >= Verifier::STACKMAP_ATTRIBUTE_MAJOR_VERSION &&
duke@0 1576 cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_stack_map_table()) {
duke@0 1577 // Stack map is only needed by the new verifier in JDK1.5.
duke@0 1578 if (parsed_stackmap_attribute) {
duke@0 1579 classfile_parse_error("Multiple StackMapTable attributes in class file %s", CHECK_(nullHandle));
duke@0 1580 }
duke@0 1581 typeArrayOop sm =
duke@0 1582 parse_stackmap_table(code_attribute_length, CHECK_(nullHandle));
duke@0 1583 stackmap_data = typeArrayHandle(THREAD, sm);
duke@0 1584 parsed_stackmap_attribute = true;
duke@0 1585 } else {
duke@0 1586 // Skip unknown attributes
duke@0 1587 cfs->skip_u1(code_attribute_length, CHECK_(nullHandle));
duke@0 1588 }
duke@0 1589 }
duke@0 1590 // check method attribute length
duke@0 1591 if (_need_verify) {
duke@0 1592 guarantee_property(method_attribute_length == calculated_attribute_length,
duke@0 1593 "Code segment has wrong length in class file %s", CHECK_(nullHandle));
duke@0 1594 }
duke@0 1595 } else if (method_attribute_name == vmSymbols::tag_exceptions()) {
duke@0 1596 // Parse Exceptions attribute
duke@0 1597 if (parsed_checked_exceptions_attribute) {
duke@0 1598 classfile_parse_error("Multiple Exceptions attributes in class file %s", CHECK_(nullHandle));
duke@0 1599 }
duke@0 1600 parsed_checked_exceptions_attribute = true;
duke@0 1601 checked_exceptions_start =
duke@0 1602 parse_checked_exceptions(&checked_exceptions_length,
duke@0 1603 method_attribute_length,
duke@0 1604 cp, CHECK_(nullHandle));
duke@0 1605 } else if (method_attribute_name == vmSymbols::tag_synthetic()) {
duke@0 1606 if (method_attribute_length != 0) {
duke@0 1607 classfile_parse_error(
duke@0 1608 "Invalid Synthetic method attribute length %u in class file %s",
duke@0 1609 method_attribute_length, CHECK_(nullHandle));
duke@0 1610 }
duke@0 1611 // Should we check that there hasn't already been a synthetic attribute?
duke@0 1612 access_flags.set_is_synthetic();
duke@0 1613 } else if (method_attribute_name == vmSymbols::tag_deprecated()) { // 4276120
duke@0 1614 if (method_attribute_length != 0) {
duke@0 1615 classfile_parse_error(
duke@0 1616 "Invalid Deprecated method attribute length %u in class file %s",
duke@0 1617 method_attribute_length, CHECK_(nullHandle));
duke@0 1618 }
duke@0 1619 } else if (_major_version >= JAVA_1_5_VERSION) {
duke@0 1620 if (method_attribute_name == vmSymbols::tag_signature()) {
duke@0 1621 if (method_attribute_length != 2) {
duke@0 1622 classfile_parse_error(
duke@0 1623 "Invalid Signature attribute length %u in class file %s",
duke@0 1624 method_attribute_length, CHECK_(nullHandle));
duke@0 1625 }
duke@0 1626 cfs->guarantee_more(2, CHECK_(nullHandle)); // generic_signature_index
duke@0 1627 generic_signature_index = cfs->get_u2_fast();
duke@0 1628 } else if (method_attribute_name == vmSymbols::tag_runtime_visible_annotations()) {
duke@0 1629 runtime_visible_annotations_length = method_attribute_length;
duke@0 1630 runtime_visible_annotations = cfs->get_u1_buffer();
duke@0 1631 assert(runtime_visible_annotations != NULL, "null visible annotations");
duke@0 1632 cfs->skip_u1(runtime_visible_annotations_length, CHECK_(nullHandle));
duke@0 1633 } else if (PreserveAllAnnotations && method_attribute_name == vmSymbols::tag_runtime_invisible_annotations()) {
duke@0 1634 runtime_invisible_annotations_length = method_attribute_length;
duke@0 1635 runtime_invisible_annotations = cfs->get_u1_buffer();
duke@0 1636 assert(runtime_invisible_annotations != NULL, "null invisible annotations");
duke@0 1637 cfs->skip_u1(runtime_invisible_annotations_length, CHECK_(nullHandle));
duke@0 1638 } else if (method_attribute_name == vmSymbols::tag_runtime_visible_parameter_annotations()) {
duke@0 1639 runtime_visible_parameter_annotations_length = method_attribute_length;
duke@0 1640 runtime_visible_parameter_annotations = cfs->get_u1_buffer();
duke@0 1641 assert(runtime_visible_parameter_annotations != NULL, "null visible parameter annotations");
duke@0 1642 cfs->skip_u1(runtime_visible_parameter_annotations_length, CHECK_(nullHandle));
duke@0 1643 } else if (PreserveAllAnnotations && method_attribute_name == vmSymbols::tag_runtime_invisible_parameter_annotations()) {
duke@0 1644 runtime_invisible_parameter_annotations_length = method_attribute_length;
duke@0 1645 runtime_invisible_parameter_annotations = cfs->get_u1_buffer();
duke@0 1646 assert(runtime_invisible_parameter_annotations != NULL, "null invisible parameter annotations");
duke@0 1647 cfs->skip_u1(runtime_invisible_parameter_annotations_length, CHECK_(nullHandle));
duke@0 1648 } else if (method_attribute_name == vmSymbols::tag_annotation_default()) {
duke@0 1649 annotation_default_length = method_attribute_length;
duke@0 1650 annotation_default = cfs->get_u1_buffer();
duke@0 1651 assert(annotation_default != NULL, "null annotation default");
duke@0 1652 cfs->skip_u1(annotation_default_length, CHECK_(nullHandle));
duke@0 1653 } else {
duke@0 1654 // Skip unknown attributes
duke@0 1655 cfs->skip_u1(method_attribute_length, CHECK_(nullHandle));
duke@0 1656 }
duke@0 1657 } else {
duke@0 1658 // Skip unknown attributes
duke@0 1659 cfs->skip_u1(method_attribute_length, CHECK_(nullHandle));
duke@0 1660 }
duke@0 1661 }
duke@0 1662
duke@0 1663 if (linenumber_table != NULL) {
duke@0 1664 linenumber_table->write_terminator();
duke@0 1665 linenumber_table_length = linenumber_table->position();
duke@0 1666 }
duke@0 1667
duke@0 1668 // Make sure there's at least one Code attribute in non-native/non-abstract method
duke@0 1669 if (_need_verify) {
duke@0 1670 guarantee_property(access_flags.is_native() || access_flags.is_abstract() || parsed_code_attribute,
duke@0 1671 "Absent Code attribute in method that is not native or abstract in class file %s", CHECK_(nullHandle));
duke@0 1672 }
duke@0 1673
duke@0 1674 // All sizing information for a methodOop is finally available, now create it
duke@0 1675 methodOop m_oop = oopFactory::new_method(
duke@0 1676 code_length, access_flags, linenumber_table_length,
jmasa@518 1677 total_lvt_length, checked_exceptions_length,
jmasa@518 1678 methodOopDesc::IsSafeConc, CHECK_(nullHandle));
duke@0 1679 methodHandle m (THREAD, m_oop);
duke@0 1680
duke@0 1681 ClassLoadingService::add_class_method_size(m_oop->size()*HeapWordSize);
duke@0 1682
duke@0 1683 // Fill in information from fixed part (access_flags already set)
duke@0 1684 m->set_constants(cp());
duke@0 1685 m->set_name_index(name_index);
duke@0 1686 m->set_signature_index(signature_index);
duke@0 1687 m->set_generic_signature_index(generic_signature_index);
duke@0 1688 #ifdef CC_INTERP
duke@0 1689 // hmm is there a gc issue here??
duke@0 1690 ResultTypeFinder rtf(cp->symbol_at(signature_index));
duke@0 1691 m->set_result_index(rtf.type());
duke@0 1692 #endif
duke@0 1693
duke@0 1694 if (args_size >= 0) {
duke@0 1695 m->set_size_of_parameters(args_size);
duke@0 1696 } else {
duke@0 1697 m->compute_size_of_parameters(THREAD);
duke@0 1698 }
duke@0 1699 #ifdef ASSERT
duke@0 1700 if (args_size >= 0) {
duke@0 1701 m->compute_size_of_parameters(THREAD);
duke@0 1702 assert(args_size == m->size_of_parameters(), "");
duke@0 1703 }
duke@0 1704 #endif
duke@0 1705
duke@0 1706 // Fill in code attribute information
duke@0 1707 m->set_max_stack(max_stack);
duke@0 1708 m->set_max_locals(max_locals);
duke@0 1709 m->constMethod()->set_stackmap_data(stackmap_data());
duke@0 1710
duke@0 1711 /**
duke@0 1712 * The exception_table field is the flag used to indicate
duke@0 1713 * that the methodOop and it's associated constMethodOop are partially
duke@0 1714 * initialized and thus are exempt from pre/post GC verification. Once
duke@0 1715 * the field is set, the oops are considered fully initialized so make
duke@0 1716 * sure that the oops can pass verification when this field is set.
duke@0 1717 */
duke@0 1718 m->set_exception_table(exception_handlers());
duke@0 1719
duke@0 1720 // Copy byte codes
duke@0 1721 if (code_length > 0) {
duke@0 1722 memcpy(m->code_base(), code_start, code_length);
duke@0 1723 }
duke@0 1724
duke@0 1725 // Copy line number table
duke@0 1726 if (linenumber_table != NULL) {
duke@0 1727 memcpy(m->compressed_linenumber_table(),
duke@0 1728 linenumber_table->buffer(), linenumber_table_length);
duke@0 1729 }
duke@0 1730
duke@0 1731 // Copy checked exceptions
duke@0 1732 if (checked_exceptions_length > 0) {
duke@0 1733 int size = checked_exceptions_length * sizeof(CheckedExceptionElement) / sizeof(u2);
duke@0 1734 copy_u2_with_conversion((u2*) m->checked_exceptions_start(), checked_exceptions_start, size);
duke@0 1735 }
duke@0 1736
duke@0 1737 /* Copy class file LVT's/LVTT's into the HotSpot internal LVT.
duke@0 1738 *
duke@0 1739 * Rules for LVT's and LVTT's are:
duke@0 1740 * - There can be any number of LVT's and LVTT's.
duke@0 1741 * - If there are n LVT's, it is the same as if there was just
duke@0 1742 * one LVT containing all the entries from the n LVT's.
duke@0 1743 * - There may be no more than one LVT entry per local variable.
duke@0 1744 * Two LVT entries are 'equal' if these fields are the same:
duke@0 1745 * start_pc, length, name, slot
duke@0 1746 * - There may be no more than one LVTT entry per each LVT entry.
duke@0 1747 * Each LVTT entry has to match some LVT entry.
duke@0 1748 * - HotSpot internal LVT keeps natural ordering of class file LVT entries.
duke@0 1749 */
duke@0 1750 if (total_lvt_length > 0) {
duke@0 1751 int tbl_no, idx;
duke@0 1752
duke@0 1753 promoted_flags->set_has_localvariable_table();
duke@0 1754
duke@0 1755 LVT_Hash** lvt_Hash = NEW_RESOURCE_ARRAY(LVT_Hash*, HASH_ROW_SIZE);
duke@0 1756 initialize_hashtable(lvt_Hash);
duke@0 1757
duke@0 1758 // To fill LocalVariableTable in
duke@0 1759 Classfile_LVT_Element* cf_lvt;
duke@0 1760 LocalVariableTableElement* lvt = m->localvariable_table_start();
duke@0 1761
duke@0 1762 for (tbl_no = 0; tbl_no < lvt_cnt; tbl_no++) {
duke@0 1763 cf_lvt = (Classfile_LVT_Element *) localvariable_table_start[tbl_no];
duke@0 1764 for (idx = 0; idx < localvariable_table_length[tbl_no]; idx++, lvt++) {
duke@0 1765 copy_lvt_element(&cf_lvt[idx], lvt);
duke@0 1766 // If no duplicates, add LVT elem in hashtable lvt_Hash.
duke@0 1767 if (LVT_put_after_lookup(lvt, lvt_Hash) == false
duke@0 1768 && _need_verify
duke@0 1769 && _major_version >= JAVA_1_5_VERSION ) {
duke@0 1770 clear_hashtable(lvt_Hash);
duke@0 1771 classfile_parse_error("Duplicated LocalVariableTable attribute "
duke@0 1772 "entry for '%s' in class file %s",
duke@0 1773 cp->symbol_at(lvt->name_cp_index)->as_utf8(),
duke@0 1774 CHECK_(nullHandle));
duke@0 1775 }
duke@0 1776 }
duke@0 1777 }
duke@0 1778
duke@0 1779 // To merge LocalVariableTable and LocalVariableTypeTable
duke@0 1780 Classfile_LVT_Element* cf_lvtt;
duke@0 1781 LocalVariableTableElement lvtt_elem;
duke@0 1782
duke@0 1783 for (tbl_no = 0; tbl_no < lvtt_cnt; tbl_no++) {
duke@0 1784 cf_lvtt = (Classfile_LVT_Element *) localvariable_type_table_start[tbl_no];
duke@0 1785 for (idx = 0; idx < localvariable_type_table_length[tbl_no]; idx++) {
duke@0 1786 copy_lvt_element(&cf_lvtt[idx], &lvtt_elem);
duke@0 1787 int index = hash(&lvtt_elem);
duke@0 1788 LVT_Hash* entry = LVT_lookup(&lvtt_elem, index, lvt_Hash);
duke@0 1789 if (entry == NULL) {
duke@0 1790 if (_need_verify) {
duke@0 1791 clear_hashtable(lvt_Hash);
duke@0 1792 classfile_parse_error("LVTT entry for '%s' in class file %s "
duke@0 1793 "does not match any LVT entry",
duke@0 1794 cp->symbol_at(lvtt_elem.name_cp_index)->as_utf8(),
duke@0 1795 CHECK_(nullHandle));
duke@0 1796 }
duke@0 1797 } else if (entry->_elem->signature_cp_index != 0 && _need_verify) {
duke@0 1798 clear_hashtable(lvt_Hash);
duke@0 1799 classfile_parse_error("Duplicated LocalVariableTypeTable attribute "
duke@0 1800 "entry for '%s' in class file %s",
duke@0 1801 cp->symbol_at(lvtt_elem.name_cp_index)->as_utf8(),
duke@0 1802 CHECK_(nullHandle));
duke@0 1803 } else {
duke@0 1804 // to add generic signatures into LocalVariableTable
duke@0 1805 entry->_elem->signature_cp_index = lvtt_elem.descriptor_cp_index;
duke@0 1806 }
duke@0 1807 }
duke@0 1808 }
duke@0 1809 clear_hashtable(lvt_Hash);
duke@0 1810 }
duke@0 1811
duke@0 1812 *method_annotations = assemble_annotations(runtime_visible_annotations,
duke@0 1813 runtime_visible_annotations_length,
duke@0 1814 runtime_invisible_annotations,
duke@0 1815 runtime_invisible_annotations_length,
duke@0 1816 CHECK_(nullHandle));
duke@0 1817 *method_parameter_annotations = assemble_annotations(runtime_visible_parameter_annotations,
duke@0 1818 runtime_visible_parameter_annotations_length,
duke@0 1819 runtime_invisible_parameter_annotations,
duke@0 1820 runtime_invisible_parameter_annotations_length,
duke@0 1821 CHECK_(nullHandle));
duke@0 1822 *method_default_annotations = assemble_annotations(annotation_default,
duke@0 1823 annotation_default_length,
duke@0 1824 NULL,
duke@0 1825 0,
duke@0 1826 CHECK_(nullHandle));
duke@0 1827
duke@0 1828 if (name() == vmSymbols::finalize_method_name() &&
duke@0 1829 signature() == vmSymbols::void_method_signature()) {
duke@0 1830 if (m->is_empty_method()) {
duke@0 1831 _has_empty_finalizer = true;
duke@0 1832 } else {
duke@0 1833 _has_finalizer = true;
duke@0 1834 }
duke@0 1835 }
duke@0 1836 if (name() == vmSymbols::object_initializer_name() &&
duke@0 1837 signature() == vmSymbols::void_method_signature() &&
duke@0 1838 m->is_vanilla_constructor()) {
duke@0 1839 _has_vanilla_constructor = true;
duke@0 1840 }
duke@0 1841
jrose@710 1842 if (EnableMethodHandles && m->is_method_handle_invoke()) {
jrose@710 1843 THROW_MSG_(vmSymbols::java_lang_VirtualMachineError(),
jrose@710 1844 "Method handle invokers must be defined internally to the VM", nullHandle);
jrose@710 1845 }
jrose@710 1846
duke@0 1847 return m;
duke@0 1848 }
duke@0 1849
duke@0 1850
duke@0 1851 // The promoted_flags parameter is used to pass relevant access_flags
duke@0 1852 // from the methods back up to the containing klass. These flag values
duke@0 1853 // are added to klass's access_flags.
duke@0 1854
duke@0 1855 objArrayHandle ClassFileParser::parse_methods(constantPoolHandle cp, bool is_interface,
duke@0 1856 AccessFlags* promoted_flags,
duke@0 1857 bool* has_final_method,
duke@0 1858 objArrayOop* methods_annotations_oop,
duke@0 1859 objArrayOop* methods_parameter_annotations_oop,
duke@0 1860 objArrayOop* methods_default_annotations_oop,
duke@0 1861 TRAPS) {
duke@0 1862 ClassFileStream* cfs = stream();
duke@0 1863 objArrayHandle nullHandle;
duke@0 1864 typeArrayHandle method_annotations;
duke@0 1865 typeArrayHandle method_parameter_annotations;
duke@0 1866 typeArrayHandle method_default_annotations;
duke@0 1867 cfs->guarantee_more(2, CHECK_(nullHandle)); // length
duke@0 1868 u2 length = cfs->get_u2_fast();
duke@0 1869 if (length == 0) {
duke@0 1870 return objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
duke@0 1871 } else {
duke@0 1872 objArrayOop m = oopFactory::new_system_objArray(length, CHECK_(nullHandle));
duke@0 1873 objArrayHandle methods(THREAD, m);
duke@0 1874 HandleMark hm(THREAD);
duke@0 1875 objArrayHandle methods_annotations;
duke@0 1876 objArrayHandle methods_parameter_annotations;
duke@0 1877 objArrayHandle methods_default_annotations;
duke@0 1878 for (int index = 0; index < length; index++) {
duke@0 1879 methodHandle method = parse_method(cp, is_interface,
duke@0 1880 promoted_flags,
duke@0 1881 &method_annotations,
duke@0 1882 &method_parameter_annotations,
duke@0 1883 &method_default_annotations,
duke@0 1884 CHECK_(nullHandle));
duke@0 1885 if (method->is_final()) {
duke@0 1886 *has_final_method = true;
duke@0 1887 }
duke@0 1888 methods->obj_at_put(index, method());
duke@0 1889 if (method_annotations.not_null()) {
duke@0 1890 if (methods_annotations.is_null()) {
duke@0 1891 objArrayOop md = oopFactory::new_system_objArray(length, CHECK_(nullHandle));
duke@0 1892 methods_annotations = objArrayHandle(THREAD, md);
duke@0 1893 }
duke@0 1894 methods_annotations->obj_at_put(index, method_annotations());
duke@0 1895 }
duke@0 1896 if (method_parameter_annotations.not_null()) {
duke@0 1897 if (methods_parameter_annotations.is_null()) {
duke@0 1898 objArrayOop md = oopFactory::new_system_objArray(length, CHECK_(nullHandle));
duke@0 1899 methods_parameter_annotations = objArrayHandle(THREAD, md);
duke@0 1900 }
duke@0 1901 methods_parameter_annotations->obj_at_put(index, method_parameter_annotations());
duke@0 1902 }
duke@0 1903 if (method_default_annotations.not_null()) {
duke@0 1904 if (methods_default_annotations.is_null()) {
duke@0 1905 objArrayOop md = oopFactory::new_system_objArray(length, CHECK_(nullHandle));
duke@0 1906 methods_default_annotations = objArrayHandle(THREAD, md);
duke@0 1907 }
duke@0 1908 methods_default_annotations->obj_at_put(index, method_default_annotations());
duke@0 1909 }
duke@0 1910 }
duke@0 1911 if (_need_verify && length > 1) {
duke@0 1912 // Check duplicated methods
duke@0 1913 ResourceMark rm(THREAD);
duke@0 1914 NameSigHash** names_and_sigs = NEW_RESOURCE_ARRAY_IN_THREAD(
duke@0 1915 THREAD, NameSigHash*, HASH_ROW_SIZE);
duke@0 1916 initialize_hashtable(names_and_sigs);
duke@0 1917 bool dup = false;
duke@0 1918 {
duke@0 1919 debug_only(No_Safepoint_Verifier nsv;)
duke@0 1920 for (int i = 0; i < length; i++) {
duke@0 1921 methodOop m = (methodOop)methods->obj_at(i);
duke@0 1922 // If no duplicates, add name/signature in hashtable names_and_sigs.
duke@0 1923 if (!put_after_lookup(m->name(), m->signature(), names_and_sigs)) {
duke@0 1924 dup = true;
duke@0 1925 break;
duke@0 1926 }
duke@0 1927 }
duke@0 1928 }
duke@0 1929 if (dup) {
duke@0 1930 classfile_parse_error("Duplicate method name&signature in class file %s",
duke@0 1931 CHECK_(nullHandle));
duke@0 1932 }
duke@0 1933 }
duke@0 1934
duke@0 1935 *methods_annotations_oop = methods_annotations();
duke@0 1936 *methods_parameter_annotations_oop = methods_parameter_annotations();
duke@0 1937 *methods_default_annotations_oop = methods_default_annotations();
duke@0 1938
duke@0 1939 return methods;
duke@0 1940 }
duke@0 1941 }
duke@0 1942
duke@0 1943
duke@0 1944 typeArrayHandle ClassFileParser::sort_methods(objArrayHandle methods,
duke@0 1945 objArrayHandle methods_annotations,
duke@0 1946 objArrayHandle methods_parameter_annotations,
duke@0 1947 objArrayHandle methods_default_annotations,
duke@0 1948 TRAPS) {
duke@0 1949 typeArrayHandle nullHandle;
duke@0 1950 int length = methods()->length();
duke@0 1951 // If JVMTI original method ordering is enabled we have to
duke@0 1952 // remember the original class file ordering.
duke@0 1953 // We temporarily use the vtable_index field in the methodOop to store the
duke@0 1954 // class file index, so we can read in after calling qsort.
duke@0 1955 if (JvmtiExport::can_maintain_original_method_order()) {
duke@0 1956 for (int index = 0; index < length; index++) {
duke@0 1957 methodOop m = methodOop(methods->obj_at(index));
duke@0 1958 assert(!m->valid_vtable_index(), "vtable index should not be set");
duke@0 1959 m->set_vtable_index(index);
duke@0 1960 }
duke@0 1961 }
duke@0 1962 // Sort method array by ascending method name (for faster lookups & vtable construction)
duke@0 1963 // Note that the ordering is not alphabetical, see symbolOopDesc::fast_compare
duke@0 1964 methodOopDesc::sort_methods(methods(),
duke@0 1965 methods_annotations(),
duke@0 1966 methods_parameter_annotations(),
duke@0 1967 methods_default_annotations());
duke@0 1968
duke@0 1969 // If JVMTI original method ordering is enabled construct int array remembering the original ordering
duke@0 1970 if (JvmtiExport::can_maintain_original_method_order()) {
duke@0 1971 typeArrayOop new_ordering = oopFactory::new_permanent_intArray(length, CHECK_(nullHandle));
duke@0 1972 typeArrayHandle method_ordering(THREAD, new_ordering);
duke@0 1973 for (int index = 0; index < length; index++) {
duke@0 1974 methodOop m = methodOop(methods->obj_at(index));
duke@0 1975 int old_index = m->vtable_index();
duke@0 1976 assert(old_index >= 0 && old_index < length, "invalid method index");
duke@0 1977 method_ordering->int_at_put(index, old_index);
duke@0 1978 m->set_vtable_index(methodOopDesc::invalid_vtable_index);
duke@0 1979 }
duke@0 1980 return method_ordering;
duke@0 1981 } else {
duke@0 1982 return typeArrayHandle(THREAD, Universe::the_empty_int_array());
duke@0 1983 }
duke@0 1984 }
duke@0 1985
duke@0 1986
duke@0 1987 void ClassFileParser::parse_classfile_sourcefile_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS) {
duke@0 1988 ClassFileStream* cfs = stream();
duke@0 1989 cfs->guarantee_more(2, CHECK); // sourcefile_index
duke@0 1990 u2 sourcefile_index = cfs->get_u2_fast();
duke@0 1991 check_property(
duke@0 1992 valid_cp_range(sourcefile_index, cp->length()) &&
duke@0 1993 cp->tag_at(sourcefile_index).is_utf8(),
duke@0 1994 "Invalid SourceFile attribute at constant pool index %u in class file %s",
duke@0 1995 sourcefile_index, CHECK);
duke@0 1996 k->set_source_file_name(cp->symbol_at(sourcefile_index));
duke@0 1997 }
duke@0 1998
duke@0 1999
duke@0 2000
duke@0 2001 void ClassFileParser::parse_classfile_source_debug_extension_attribute(constantPoolHandle cp,
duke@0 2002 instanceKlassHandle k,
duke@0 2003 int length, TRAPS) {
duke@0 2004 ClassFileStream* cfs = stream();
duke@0 2005 u1* sde_buffer = cfs->get_u1_buffer();
duke@0 2006 assert(sde_buffer != NULL, "null sde buffer");
duke@0 2007
duke@0 2008 // Don't bother storing it if there is no way to retrieve it
duke@0 2009 if (JvmtiExport::can_get_source_debug_extension()) {
duke@0 2010 // Optimistically assume that only 1 byte UTF format is used
duke@0 2011 // (common case)
duke@0 2012 symbolOop sde_symbol = oopFactory::new_symbol((char*)sde_buffer,
duke@0 2013 length, CHECK);
duke@0 2014 k->set_source_debug_extension(sde_symbol);
duke@0 2015 }
duke@0 2016 // Got utf8 string, set stream position forward
duke@0 2017 cfs->skip_u1(length, CHECK);
duke@0 2018 }
duke@0 2019
duke@0 2020
duke@0 2021 // Inner classes can be static, private or protected (classic VM does this)
duke@0 2022 #define RECOGNIZED_INNER_CLASS_MODIFIERS (JVM_RECOGNIZED_CLASS_MODIFIERS | JVM_ACC_PRIVATE | JVM_ACC_PROTECTED | JVM_ACC_STATIC)
duke@0 2023
duke@0 2024 // Return number of classes in the inner classes attribute table
duke@0 2025 u2 ClassFileParser::parse_classfile_inner_classes_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS) {
duke@0 2026 ClassFileStream* cfs = stream();
duke@0 2027 cfs->guarantee_more(2, CHECK_0); // length
duke@0 2028 u2 length = cfs->get_u2_fast();
duke@0 2029
duke@0 2030 // 4-tuples of shorts [inner_class_info_index, outer_class_info_index, inner_name_index, inner_class_access_flags]
duke@0 2031 typeArrayOop ic = oopFactory::new_permanent_shortArray(length*4, CHECK_0);
duke@0 2032 typeArrayHandle inner_classes(THREAD, ic);
duke@0 2033 int index = 0;
duke@0 2034 int cp_size = cp->length();
duke@0 2035 cfs->guarantee_more(8 * length, CHECK_0); // 4-tuples of u2
duke@0 2036 for (int n = 0; n < length; n++) {
duke@0 2037 // Inner class index
duke@0 2038 u2 inner_class_info_index = cfs->get_u2_fast();
duke@0 2039 check_property(
duke@0 2040 inner_class_info_index == 0 ||
duke@0 2041 (valid_cp_range(inner_class_info_index, cp_size) &&
jrose@431 2042 is_klass_reference(cp, inner_class_info_index)),
duke@0 2043 "inner_class_info_index %u has bad constant type in class file %s",
duke@0 2044 inner_class_info_index, CHECK_0);
duke@0 2045 // Outer class index
duke@0 2046 u2 outer_class_info_index = cfs->get_u2_fast();
duke@0 2047 check_property(
duke@0 2048 outer_class_info_index == 0 ||
duke@0 2049 (valid_cp_range(outer_class_info_index, cp_size) &&
jrose@431 2050 is_klass_reference(cp, outer_class_info_index)),
duke@0 2051 "outer_class_info_index %u has bad constant type in class file %s",
duke@0 2052 outer_class_info_index, CHECK_0);
duke@0 2053 // Inner class name
duke@0 2054 u2 inner_name_index = cfs->get_u2_fast();
duke@0 2055 check_property(
duke@0 2056 inner_name_index == 0 || (valid_cp_range(inner_name_index, cp_size) &&
duke@0 2057 cp->tag_at(inner_name_index).is_utf8()),
duke@0 2058 "inner_name_index %u has bad constant type in class file %s",
duke@0 2059 inner_name_index, CHECK_0);
duke@0 2060 if (_need_verify) {
duke@0 2061 guarantee_property(inner_class_info_index != outer_class_info_index,
duke@0 2062 "Class is both outer and inner class in class file %s", CHECK_0);
duke@0 2063 }
duke@0 2064 // Access flags
duke@0 2065 AccessFlags inner_access_flags;
duke@0 2066 jint flags = cfs->get_u2_fast() & RECOGNIZED_INNER_CLASS_MODIFIERS;
duke@0 2067 if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
duke@0 2068 // Set abstract bit for old class files for backward compatibility
duke@0 2069 flags |= JVM_ACC_ABSTRACT;
duke@0 2070 }
duke@0 2071 verify_legal_class_modifiers(flags, CHECK_0);
duke@0 2072 inner_access_flags.set_flags(flags);
duke@0 2073
duke@0 2074 inner_classes->short_at_put(index++, inner_class_info_index);
duke@0 2075 inner_classes->short_at_put(index++, outer_class_info_index);
duke@0 2076 inner_classes->short_at_put(index++, inner_name_index);
duke@0 2077 inner_classes->short_at_put(index++, inner_access_flags.as_short());
duke@0 2078 }
duke@0 2079
duke@0 2080 // 4347400: make sure there's no duplicate entry in the classes array
duke@0 2081 if (_need_verify && _major_version >= JAVA_1_5_VERSION) {
duke@0 2082 for(int i = 0; i < inner_classes->length(); i += 4) {
duke@0 2083 for(int j = i + 4; j < inner_classes->length(); j += 4) {
duke@0 2084 guarantee_property((inner_classes->ushort_at(i) != inner_classes->ushort_at(j) ||
duke@0 2085 inner_classes->ushort_at(i+1) != inner_classes->ushort_at(j+1) ||
duke@0 2086 inner_classes->ushort_at(i+2) != inner_classes->ushort_at(j+2) ||
duke@0 2087 inner_classes->ushort_at(i+3) != inner_classes->ushort_at(j+3)),
duke@0 2088 "Duplicate entry in InnerClasses in class file %s",
duke@0 2089 CHECK_0);
duke@0 2090 }
duke@0 2091 }
duke@0 2092 }
duke@0 2093
duke@0 2094 // Update instanceKlass with inner class info.
duke@0 2095 k->set_inner_classes(inner_classes());
duke@0 2096 return length;
duke@0 2097 }
duke@0 2098
duke@0 2099 void ClassFileParser::parse_classfile_synthetic_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS) {
duke@0 2100 k->set_is_synthetic();
duke@0 2101 }
duke@0 2102
duke@0 2103 void ClassFileParser::parse_classfile_signature_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS) {
duke@0 2104 ClassFileStream* cfs = stream();
duke@0 2105 u2 signature_index = cfs->get_u2(CHECK);
duke@0 2106 check_property(
duke@0 2107 valid_cp_range(signature_index, cp->length()) &&
duke@0 2108 cp->tag_at(signature_index).is_utf8(),
duke@0 2109 "Invalid constant pool index %u in Signature attribute in class file %s",
duke@0 2110 signature_index, CHECK);
duke@0 2111 k->set_generic_signature(cp->symbol_at(signature_index));
duke@0 2112 }
duke@0 2113
duke@0 2114 void ClassFileParser::parse_classfile_attributes(constantPoolHandle cp, instanceKlassHandle k, TRAPS) {
duke@0 2115 ClassFileStream* cfs = stream();
duke@0 2116 // Set inner classes attribute to default sentinel
duke@0 2117 k->set_inner_classes(Universe::the_empty_short_array());
duke@0 2118 cfs->guarantee_more(2, CHECK); // attributes_count
duke@0 2119 u2 attributes_count = cfs->get_u2_fast();
duke@0 2120 bool parsed_sourcefile_attribute = false;
duke@0 2121 bool parsed_innerclasses_attribute = false;
duke@0 2122 bool parsed_enclosingmethod_attribute = false;
duke@0 2123 u1* runtime_visible_annotations = NULL;
duke@0 2124 int runtime_visible_annotations_length = 0;
duke@0 2125 u1* runtime_invisible_annotations = NULL;
duke@0 2126 int runtime_invisible_annotations_length = 0;
duke@0 2127 // Iterate over attributes
duke@0 2128 while (attributes_count--) {
duke@0 2129 cfs->guarantee_more(6, CHECK); // attribute_name_index, attribute_length
duke@0 2130 u2 attribute_name_index = cfs->get_u2_fast();
duke@0 2131 u4 attribute_length = cfs->get_u4_fast();
duke@0 2132 check_property(
duke@0 2133 valid_cp_range(attribute_name_index, cp->length()) &&
duke@0 2134 cp->tag_at(attribute_name_index).is_utf8(),
duke@0 2135 "Attribute name has bad constant pool index %u in class file %s",
duke@0 2136 attribute_name_index, CHECK);
duke@0 2137 symbolOop tag = cp->symbol_at(attribute_name_index);
duke@0 2138 if (tag == vmSymbols::tag_source_file()) {
duke@0 2139 // Check for SourceFile tag
duke@0 2140 if (_need_verify) {
duke@0 2141 guarantee_property(attribute_length == 2, "Wrong SourceFile attribute length in class file %s", CHECK);
duke@0 2142 }
duke@0 2143 if (parsed_sourcefile_attribute) {
duke@0 2144 classfile_parse_error("Multiple SourceFile attributes in class file %s", CHECK);
duke@0 2145 } else {
duke@0 2146 parsed_sourcefile_attribute = true;
duke@0 2147 }
duke@0 2148 parse_classfile_sourcefile_attribute(cp, k, CHECK);
duke@0 2149 } else if (tag == vmSymbols::tag_source_debug_extension()) {
duke@0 2150 // Check for SourceDebugExtension tag
duke@0 2151 parse_classfile_source_debug_extension_attribute(cp, k, (int)attribute_length, CHECK);
duke@0 2152 } else if (tag == vmSymbols::tag_inner_classes()) {
duke@0 2153 // Check for InnerClasses tag
duke@0 2154 if (parsed_innerclasses_attribute) {
duke@0 2155 classfile_parse_error("Multiple InnerClasses attributes in class file %s", CHECK);
duke@0 2156 } else {
duke@0 2157 parsed_innerclasses_attribute = true;
duke@0 2158 }
duke@0 2159 u2 num_of_classes = parse_classfile_inner_classes_attribute(cp, k, CHECK);
duke@0 2160 if (_need_verify && _major_version >= JAVA_1_5_VERSION) {
duke@0 2161 guarantee_property(attribute_length == sizeof(num_of_classes) + 4 * sizeof(u2) * num_of_classes,
duke@0 2162 "Wrong InnerClasses attribute length in class file %s", CHECK);
duke@0 2163 }
duke@0 2164 } else if (tag == vmSymbols::tag_synthetic()) {
duke@0 2165 // Check for Synthetic tag
duke@0 2166 // Shouldn't we check that the synthetic flags wasn't already set? - not required in spec
duke@0 2167 if (attribute_length != 0) {
duke@0 2168 classfile_parse_error(
duke@0 2169 "Invalid Synthetic classfile attribute length %u in class file %s",
duke@0 2170 attribute_length, CHECK);
duke@0 2171 }
duke@0 2172 parse_classfile_synthetic_attribute(cp, k, CHECK);
duke@0 2173 } else if (tag == vmSymbols::tag_deprecated()) {
duke@0 2174 // Check for Deprecatd tag - 4276120
duke@0 2175 if (attribute_length != 0) {
duke@0 2176 classfile_parse_error(
duke@0 2177 "Invalid Deprecated classfile attribute length %u in class file %s",
duke@0 2178 attribute_length, CHECK);
duke@0 2179 }
duke@0 2180 } else if (_major_version >= JAVA_1_5_VERSION) {
duke@0 2181 if (tag == vmSymbols::tag_signature()) {
duke@0 2182 if (attribute_length != 2) {
duke@0 2183 classfile_parse_error(
duke@0 2184 "Wrong Signature attribute length %u in class file %s",
duke@0 2185 attribute_length, CHECK);
duke@0 2186 }
duke@0 2187 parse_classfile_signature_attribute(cp, k, CHECK);
duke@0 2188 } else if (tag == vmSymbols::tag_runtime_visible_annotations()) {
duke@0 2189 runtime_visible_annotations_length = attribute_length;
duke@0 2190 runtime_visible_annotations = cfs->get_u1_buffer();
duke@0 2191 assert(runtime_visible_annotations != NULL, "null visible annotations");
duke@0 2192 cfs->skip_u1(runtime_visible_annotations_length, CHECK);
duke@0 2193 } else if (PreserveAllAnnotations && tag == vmSymbols::tag_runtime_invisible_annotations()) {
duke@0 2194 runtime_invisible_annotations_length = attribute_length;
duke@0 2195 runtime_invisible_annotations = cfs->get_u1_buffer();
duke@0 2196 assert(runtime_invisible_annotations != NULL, "null invisible annotations");
duke@0 2197 cfs->skip_u1(runtime_invisible_annotations_length, CHECK);
duke@0 2198 } else if (tag == vmSymbols::tag_enclosing_method()) {
duke@0 2199 if (parsed_enclosingmethod_attribute) {
duke@0 2200 classfile_parse_error("Multiple EnclosingMethod attributes in class file %s", CHECK);
duke@0 2201 } else {
duke@0 2202 parsed_enclosingmethod_attribute = true;
duke@0 2203 }
duke@0 2204 cfs->guarantee_more(4, CHECK); // class_index, method_index
duke@0 2205 u2 class_index = cfs->get_u2_fast();
duke@0 2206 u2 method_index = cfs->get_u2_fast();
duke@0 2207 if (class_index == 0) {
duke@0 2208 classfile_parse_error("Invalid class index in EnclosingMethod attribute in class file %s", CHECK);
duke@0 2209 }
duke@0 2210 // Validate the constant pool indices and types
duke@0 2211 if (!cp->is_within_bounds(class_index) ||
jrose@431 2212 !is_klass_reference(cp, class_index)) {
duke@0 2213 classfile_parse_error("Invalid or out-of-bounds class index in EnclosingMethod attribute in class file %s", CHECK);
duke@0 2214 }
duke@0 2215 if (method_index != 0 &&
duke@0 2216 (!cp->is_within_bounds(method_index) ||
duke@0 2217 !cp->tag_at(method_index).is_name_and_type())) {
duke@0 2218 classfile_parse_error("Invalid or out-of-bounds method index in EnclosingMethod attribute in class file %s", CHECK);
duke@0 2219 }
duke@0 2220 k->set_enclosing_method_indices(class_index, method_index);
duke@0 2221 } else {
duke@0 2222 // Unknown attribute
duke@0 2223 cfs->skip_u1(attribute_length, CHECK);
duke@0 2224 }
duke@0 2225 } else {
duke@0 2226 // Unknown attribute
duke@0 2227 cfs->skip_u1(attribute_length, CHECK);
duke@0 2228 }
duke@0 2229 }
duke@0 2230 typeArrayHandle annotations = assemble_annotations(runtime_visible_annotations,
duke@0 2231 runtime_visible_annotations_length,
duke@0 2232 runtime_invisible_annotations,
duke@0 2233 runtime_invisible_annotations_length,
duke@0 2234 CHECK);
duke@0 2235 k->set_class_annotations(annotations());
duke@0 2236 }
duke@0 2237
duke@0 2238
duke@0 2239 typeArrayHandle ClassFileParser::assemble_annotations(u1* runtime_visible_annotations,
duke@0 2240 int runtime_visible_annotations_length,
duke@0 2241 u1* runtime_invisible_annotations,
duke@0 2242 int runtime_invisible_annotations_length, TRAPS) {
duke@0 2243 typeArrayHandle annotations;
duke@0 2244 if (runtime_visible_annotations != NULL ||
duke@0 2245 runtime_invisible_annotations != NULL) {
duke@0 2246 typeArrayOop anno = oopFactory::new_permanent_byteArray(runtime_visible_annotations_length +
duke@0 2247 runtime_invisible_annotations_length, CHECK_(annotations));
duke@0 2248 annotations = typeArrayHandle(THREAD, anno);
duke@0 2249 if (runtime_visible_annotations != NULL) {
duke@0 2250 memcpy(annotations->byte_at_addr(0), runtime_visible_annotations, runtime_visible_annotations_length);
duke@0 2251 }
duke@0 2252 if (runtime_invisible_annotations != NULL) {
duke@0 2253 memcpy(annotations->byte_at_addr(runtime_visible_annotations_length), runtime_invisible_annotations, runtime_invisible_annotations_length);
duke@0 2254 }
duke@0 2255 }
duke@0 2256 return annotations;
duke@0 2257 }
duke@0 2258
duke@0 2259
duke@0 2260 static void initialize_static_field(fieldDescriptor* fd, TRAPS) {
duke@0 2261 KlassHandle h_k (THREAD, fd->field_holder());
duke@0 2262 assert(h_k.not_null() && fd->is_static(), "just checking");
duke@0 2263 if (fd->has_initial_value()) {
duke@0 2264 BasicType t = fd->field_type();
duke@0 2265 switch (t) {
duke@0 2266 case T_BYTE:
duke@0 2267 h_k()->byte_field_put(fd->offset(), fd->int_initial_value());
duke@0 2268 break;
duke@0 2269 case T_BOOLEAN:
duke@0 2270 h_k()->bool_field_put(fd->offset(), fd->int_initial_value());
duke@0 2271 break;
duke@0 2272 case T_CHAR:
duke@0 2273 h_k()->char_field_put(fd->offset(), fd->int_initial_value());
duke@0 2274 break;
duke@0 2275 case T_SHORT:
duke@0 2276 h_k()->short_field_put(fd->offset(), fd->int_initial_value());
duke@0 2277 break;
duke@0 2278 case T_INT:
duke@0 2279 h_k()->int_field_put(fd->offset(), fd->int_initial_value());
duke@0 2280 break;
duke@0 2281 case T_FLOAT:
duke@0 2282 h_k()->float_field_put(fd->offset(), fd->float_initial_value());
duke@0 2283 break;
duke@0 2284 case T_DOUBLE:
duke@0 2285 h_k()->double_field_put(fd->offset(), fd->double_initial_value());
duke@0 2286 break;
duke@0 2287 case T_LONG:
duke@0 2288 h_k()->long_field_put(fd->offset(), fd->long_initial_value());
duke@0 2289 break;
duke@0 2290 case T_OBJECT:
duke@0 2291 {
duke@0 2292 #ifdef ASSERT
duke@0 2293 symbolOop sym = oopFactory::new_symbol("Ljava/lang/String;", CHECK);
duke@0 2294 assert(fd->signature() == sym, "just checking");
duke@0 2295 #endif
duke@0 2296 oop string = fd->string_initial_value(CHECK);
duke@0 2297 h_k()->obj_field_put(fd->offset(), string);
duke@0 2298 }
duke@0 2299 break;
duke@0 2300 default:
duke@0 2301 THROW_MSG(vmSymbols::java_lang_ClassFormatError(),
duke@0 2302 "Illegal ConstantValue attribute in class file");
duke@0 2303 }
duke@0 2304 }
duke@0 2305 }
duke@0 2306
duke@0 2307
duke@0 2308 void ClassFileParser::java_lang_ref_Reference_fix_pre(typeArrayHandle* fields_ptr,
duke@0 2309 constantPoolHandle cp, FieldAllocationCount *fac_ptr, TRAPS) {
duke@0 2310 // This code is for compatibility with earlier jdk's that do not
duke@0 2311 // have the "discovered" field in java.lang.ref.Reference. For 1.5
duke@0 2312 // the check for the "discovered" field should issue a warning if
duke@0 2313 // the field is not found. For 1.6 this code should be issue a
duke@0 2314 // fatal error if the "discovered" field is not found.
duke@0 2315 //
duke@0 2316 // Increment fac.nonstatic_oop_count so that the start of the
duke@0 2317 // next type of non-static oops leaves room for the fake oop.
duke@0 2318 // Do not increment next_nonstatic_oop_offset so that the
duke@0 2319 // fake oop is place after the java.lang.ref.Reference oop
duke@0 2320 // fields.
duke@0 2321 //
duke@0 2322 // Check the fields in java.lang.ref.Reference for the "discovered"
duke@0 2323 // field. If it is not present, artifically create a field for it.
duke@0 2324 // This allows this VM to run on early JDK where the field is not
duke@0 2325 // present.
duke@0 2326
duke@0 2327 //
duke@0 2328 // Increment fac.nonstatic_oop_count so that the start of the
duke@0 2329 // next type of non-static oops leaves room for the fake oop.
duke@0 2330 // Do not increment next_nonstatic_oop_offset so that the
duke@0 2331 // fake oop is place after the java.lang.ref.Reference oop
duke@0 2332 // fields.
duke@0 2333 //
duke@0 2334 // Check the fields in java.lang.ref.Reference for the "discovered"
duke@0 2335 // field. If it is not present, artifically create a field for it.
duke@0 2336 // This allows this VM to run on early JDK where the field is not
duke@0 2337 // present.
duke@0 2338 int reference_sig_index = 0;
duke@0 2339 int reference_name_index = 0;
duke@0 2340 int reference_index = 0;
duke@0 2341 int extra = java_lang_ref_Reference::number_of_fake_oop_fields;
duke@0 2342 const int n = (*fields_ptr)()->length();
duke@0 2343 for (int i = 0; i < n; i += instanceKlass::next_offset ) {
duke@0 2344 int name_index =
duke@0 2345 (*fields_ptr)()->ushort_at(i + instanceKlass::name_index_offset);
duke@0 2346 int sig_index =
duke@0 2347 (*fields_ptr)()->ushort_at(i + instanceKlass::signature_index_offset);
duke@0 2348 symbolOop f_name = cp->symbol_at(name_index);
duke@0 2349 symbolOop f_sig = cp->symbol_at(sig_index);
duke@0 2350 if (f_sig == vmSymbols::reference_signature() && reference_index == 0) {
duke@0 2351 // Save the index for reference signature for later use.
duke@0 2352 // The fake discovered field does not entries in the
duke@0 2353 // constant pool so the index for its signature cannot
duke@0 2354 // be extracted from the constant pool. It will need
duke@0 2355 // later, however. It's signature is vmSymbols::reference_signature()
duke@0 2356 // so same an index for that signature.
duke@0 2357 reference_sig_index = sig_index;
duke@0 2358 reference_name_index = name_index;
duke@0 2359 reference_index = i;
duke@0 2360 }
duke@0 2361 if (f_name == vmSymbols::reference_discovered_name() &&
duke@0 2362 f_sig == vmSymbols::reference_signature()) {
duke@0 2363 // The values below are fake but will force extra
duke@0 2364 // non-static oop fields and a corresponding non-static
duke@0 2365 // oop map block to be allocated.
duke@0 2366 extra = 0;
duke@0 2367 break;
duke@0 2368 }
duke@0 2369 }
duke@0 2370 if (extra != 0) {
duke@0 2371 fac_ptr->nonstatic_oop_count += extra;
duke@0 2372 // Add the additional entry to "fields" so that the klass
duke@0 2373 // contains the "discoverd" field and the field will be initialized
duke@0 2374 // in instances of the object.
duke@0 2375 int fields_with_fix_length = (*fields_ptr)()->length() +
duke@0 2376 instanceKlass::next_offset;
duke@0 2377 typeArrayOop ff = oopFactory::new_permanent_shortArray(
duke@0 2378 fields_with_fix_length, CHECK);
duke@0 2379 typeArrayHandle fields_with_fix(THREAD, ff);
duke@0 2380
duke@0 2381 // Take everything from the original but the length.
duke@0 2382 for (int idx = 0; idx < (*fields_ptr)->length(); idx++) {
duke@0 2383 fields_with_fix->ushort_at_put(idx, (*fields_ptr)->ushort_at(idx));
duke@0 2384 }
duke@0 2385
duke@0 2386 // Add the fake field at the end.
duke@0 2387 int i = (*fields_ptr)->length();
duke@0 2388 // There is no name index for the fake "discovered" field nor
duke@0 2389 // signature but a signature is needed so that the field will
duke@0 2390 // be properly initialized. Use one found for
duke@0 2391 // one of the other reference fields. Be sure the index for the
duke@0 2392 // name is 0. In fieldDescriptor::initialize() the index of the
duke@0 2393 // name is checked. That check is by passed for the last nonstatic
duke@0 2394 // oop field in a java.lang.ref.Reference which is assumed to be
duke@0 2395 // this artificial "discovered" field. An assertion checks that
duke@0 2396 // the name index is 0.
duke@0 2397 assert(reference_index != 0, "Missing signature for reference");
duke@0 2398
duke@0 2399 int j;
duke@0 2400 for (j = 0; j < instanceKlass::next_offset; j++) {
duke@0 2401 fields_with_fix->ushort_at_put(i + j,
duke@0 2402 (*fields_ptr)->ushort_at(reference_index +j));
duke@0 2403 }
duke@0 2404 // Clear the public access flag and set the private access flag.
duke@0 2405 short flags;
duke@0 2406 flags =
duke@0 2407 fields_with_fix->ushort_at(i + instanceKlass::access_flags_offset);
duke@0 2408 assert(!(flags & JVM_RECOGNIZED_FIELD_MODIFIERS), "Unexpected access flags set");
duke@0 2409 flags = flags & (~JVM_ACC_PUBLIC);
duke@0 2410 flags = flags | JVM_ACC_PRIVATE;
duke@0 2411 AccessFlags access_flags;
duke@0 2412 access_flags.set_flags(flags);
duke@0 2413 assert(!access_flags.is_public(), "Failed to clear public flag");
duke@0 2414 assert(access_flags.is_private(), "Failed to set private flag");
duke@0 2415 fields_with_fix->ushort_at_put(i + instanceKlass::access_flags_offset,
duke@0 2416 flags);
duke@0 2417
duke@0 2418 assert(fields_with_fix->ushort_at(i + instanceKlass::name_index_offset)
duke@0 2419 == reference_name_index, "The fake reference name is incorrect");
duke@0 2420 assert(fields_with_fix->ushort_at(i + instanceKlass::signature_index_offset)
duke@0 2421 == reference_sig_index, "The fake reference signature is incorrect");
duke@0 2422 // The type of the field is stored in the low_offset entry during
duke@0 2423 // parsing.
duke@0 2424 assert(fields_with_fix->ushort_at(i + instanceKlass::low_offset) ==
duke@0 2425 NONSTATIC_OOP, "The fake reference type is incorrect");
duke@0 2426
duke@0 2427 // "fields" is allocated in the permanent generation. Disgard
duke@0 2428 // it and let it be collected.
duke@0 2429 (*fields_ptr) = fields_with_fix;
duke@0 2430 }
duke@0 2431 return;
duke@0 2432 }
duke@0 2433
duke@0 2434
duke@0 2435 void ClassFileParser::java_lang_Class_fix_pre(objArrayHandle* methods_ptr,
duke@0 2436 FieldAllocationCount *fac_ptr, TRAPS) {
duke@0 2437 // Add fake fields for java.lang.Class instances
duke@0 2438 //
duke@0 2439 // This is not particularly nice. We should consider adding a
duke@0 2440 // private transient object field at the Java level to
duke@0 2441 // java.lang.Class. Alternatively we could add a subclass of
duke@0 2442 // instanceKlass which provides an accessor and size computer for
duke@0 2443 // this field, but that appears to be more code than this hack.
duke@0 2444 //
duke@0 2445 // NOTE that we wedge these in at the beginning rather than the
duke@0 2446 // end of the object because the Class layout changed between JDK
duke@0 2447 // 1.3 and JDK 1.4 with the new reflection implementation; some
duke@0 2448 // nonstatic oop fields were added at the Java level. The offsets
duke@0 2449 // of these fake fields can't change between these two JDK
duke@0 2450 // versions because when the offsets are computed at bootstrap
duke@0 2451 // time we don't know yet which version of the JDK we're running in.
duke@0 2452
duke@0 2453 // The values below are fake but will force two non-static oop fields and
duke@0 2454 // a corresponding non-static oop map block to be allocated.
duke@0 2455 const int extra = java_lang_Class::number_of_fake_oop_fields;
duke@0 2456 fac_ptr->nonstatic_oop_count += extra;
duke@0 2457 }
duke@0 2458
duke@0 2459
duke@0 2460 void ClassFileParser::java_lang_Class_fix_post(int* next_nonstatic_oop_offset_ptr) {
duke@0 2461 // Cause the extra fake fields in java.lang.Class to show up before
duke@0 2462 // the Java fields for layout compatibility between 1.3 and 1.4
duke@0 2463 // Incrementing next_nonstatic_oop_offset here advances the
duke@0 2464 // location where the real java fields are placed.
duke@0 2465 const int extra = java_lang_Class::number_of_fake_oop_fields;
coleenp@113 2466 (*next_nonstatic_oop_offset_ptr) += (extra * heapOopSize);
duke@0 2467 }
duke@0 2468
duke@0 2469
jrose@710 2470 // Force MethodHandle.vmentry to be an unmanaged pointer.
jrose@710 2471 // There is no way for a classfile to express this, so we must help it.
jrose@710 2472 void ClassFileParser::java_dyn_MethodHandle_fix_pre(constantPoolHandle cp,
jrose@710 2473 typeArrayHandle* fields_ptr,
jrose@710 2474 FieldAllocationCount *fac_ptr,
jrose@710 2475 TRAPS) {
jrose@710 2476 // Add fake fields for java.dyn.MethodHandle instances
jrose@710 2477 //
jrose@710 2478 // This is not particularly nice, but since there is no way to express
jrose@710 2479 // a native wordSize field in Java, we must do it at this level.
jrose@710 2480
jrose@710 2481 if (!EnableMethodHandles) return;
jrose@710 2482
jrose@710 2483 int word_sig_index = 0;
jrose@710 2484 const int cp_size = cp->length();
jrose@710 2485 for (int index = 1; index < cp_size; index++) {
jrose@710 2486 if (cp->tag_at(index).is_utf8() &&
jrose@710 2487 cp->symbol_at(index) == vmSymbols::machine_word_signature()) {
jrose@710 2488 word_sig_index = index;
jrose@710 2489 break;
jrose@710 2490 }
jrose@710 2491 }
jrose@710 2492
jrose@710 2493 if (word_sig_index == 0)
jrose@710 2494 THROW_MSG(vmSymbols::java_lang_VirtualMachineError(),
jrose@710 2495 "missing I or J signature (for vmentry) in java.dyn.MethodHandle");
jrose@710 2496
jrose@710 2497 bool found_vmentry = false;
jrose@710 2498
jrose@710 2499 const int n = (*fields_ptr)()->length();
jrose@710 2500 for (int i = 0; i < n; i += instanceKlass::next_offset) {
jrose@710 2501 int name_index = (*fields_ptr)->ushort_at(i + instanceKlass::name_index_offset);
jrose@710 2502 int sig_index = (*fields_ptr)->ushort_at(i + instanceKlass::signature_index_offset);
jrose@710 2503 int acc_flags = (*fields_ptr)->ushort_at(i + instanceKlass::access_flags_offset);
jrose@710 2504 symbolOop f_name = cp->symbol_at(name_index);
jrose@710 2505 symbolOop f_sig = cp->symbol_at(sig_index);
jrose@710 2506 if (f_sig == vmSymbols::byte_signature() &&
jrose@710 2507 f_name == vmSymbols::vmentry_name() &&
jrose@710 2508 (acc_flags & JVM_ACC_STATIC) == 0) {
jrose@710 2509 // Adjust the field type from byte to an unmanaged pointer.
jrose@710 2510 assert(fac_ptr->nonstatic_byte_count > 0, "");
jrose@710 2511 fac_ptr->nonstatic_byte_count -= 1;
jrose@710 2512 (*fields_ptr)->ushort_at_put(i + instanceKlass::signature_index_offset,
jrose@710 2513 word_sig_index);
jrose@710 2514 if (wordSize == jintSize) {
jrose@710 2515 fac_ptr->nonstatic_word_count += 1;
jrose@710 2516 } else {
jrose@710 2517 fac_ptr->nonstatic_double_count += 1;
jrose@710 2518 }
jrose@710 2519
jrose@710 2520 FieldAllocationType atype = (FieldAllocationType) (*fields_ptr)->ushort_at(i+4);
jrose@710 2521 assert(atype == NONSTATIC_BYTE, "");
jrose@710 2522 FieldAllocationType new_atype = NONSTATIC_WORD;
jrose@710 2523 if (wordSize > jintSize) {
jrose@710 2524 if (Universe::field_type_should_be_aligned(T_LONG)) {
jrose@710 2525 atype = NONSTATIC_ALIGNED_DOUBLE;
jrose@710 2526 } else {
jrose@710 2527 atype = NONSTATIC_DOUBLE;
jrose@710 2528 }
jrose@710 2529 }
jrose@710 2530 (*fields_ptr)->ushort_at_put(i+4, new_atype);
jrose@710 2531
jrose@710 2532 found_vmentry = true;
jrose@710 2533 break;
jrose@710 2534 }
jrose@710 2535 }
jrose@710 2536
jrose@710 2537 if (!found_vmentry)
jrose@710 2538 THROW_MSG(vmSymbols::java_lang_VirtualMachineError(),
jrose@710 2539 "missing vmentry byte field in java.dyn.MethodHandle");
jrose@710 2540
jrose@710 2541 }
jrose@710 2542
jrose@710 2543
duke@0 2544 instanceKlassHandle ClassFileParser::parseClassFile(symbolHandle name,
duke@0 2545 Handle class_loader,
duke@0 2546 Handle protection_domain,
jrose@710 2547 KlassHandle host_klass,
jrose@431 2548 GrowableArray<Handle>* cp_patches,
duke@0 2549 symbolHandle& parsed_name,
acorn@973 2550 bool verify,
duke@0 2551 TRAPS) {
duke@0 2552 // So that JVMTI can cache class file in the state before retransformable agents
duke@0 2553 // have modified it
duke@0 2554 unsigned char *cached_class_file_bytes = NULL;
duke@0 2555 jint cached_class_file_length;
duke@0 2556
duke@0 2557 ClassFileStream* cfs = stream();
duke@0 2558 // Timing
mchung@875 2559 assert(THREAD->is_Java_thread(), "must be a JavaThread");
mchung@875 2560 JavaThread* jt = (JavaThread*) THREAD;
mchung@875 2561
mchung@875 2562 PerfClassTraceTime ctimer(ClassLoader::perf_class_parse_time(),
mchung@875 2563 ClassLoader::perf_class_parse_selftime(),
mchung@875 2564 NULL,
mchung@875 2565 jt->get_thread_stat()->perf_recursion_counts_addr(),
mchung@875 2566 jt->get_thread_stat()->perf_timers_addr(),
mchung@875 2567 PerfClassTraceTime::PARSE_CLASS);
duke@0 2568
duke@0 2569 _has_finalizer = _has_empty_finalizer = _has_vanilla_constructor = false;
duke@0 2570
duke@0 2571 if (JvmtiExport::should_post_class_file_load_hook()) {
duke@0 2572 unsigned char* ptr = cfs->buffer();
duke@0 2573 unsigned char* end_ptr = cfs->buffer() + cfs->length();
duke@0 2574
duke@0 2575 JvmtiExport::post_class_file_load_hook(name, class_loader, protection_domain,
duke@0 2576 &ptr, &end_ptr,
duke@0 2577 &cached_class_file_bytes,
duke@0 2578 &cached_class_file_length);
duke@0 2579
duke@0 2580 if (ptr != cfs->buffer()) {
duke@0 2581 // JVMTI agent has modified class file data.
duke@0 2582 // Set new class file stream using JVMTI agent modified
duke@0 2583 // class file data.
duke@0 2584 cfs = new ClassFileStream(ptr, end_ptr - ptr, cfs->source());
duke@0 2585 set_stream(cfs);
duke@0 2586 }
duke@0 2587 }
duke@0 2588
jrose@710 2589 _host_klass = host_klass;
jrose@431 2590 _cp_patches = cp_patches;
duke@0 2591
duke@0 2592 instanceKlassHandle nullHandle;
duke@0 2593
duke@0 2594 // Figure out whether we can skip format checking (matching classic VM behavior)
acorn@973 2595 _need_verify = Verifier::should_verify_for(class_loader(), verify);
duke@0 2596
duke@0 2597 // Set the verify flag in stream
duke@0 2598 cfs->set_verify(_need_verify);
duke@0 2599
duke@0 2600 // Save the class file name for easier error message printing.
duke@0 2601 _class_name = name.not_null()? name : vmSymbolHandles::unknown_class_name();
duke@0 2602
duke@0 2603 cfs->guarantee_more(8, CHECK_(nullHandle)); // magic, major, minor
duke@0 2604 // Magic value
duke@0 2605 u4 magic = cfs->get_u4_fast();
duke@0 2606 guarantee_property(magic == JAVA_CLASSFILE_MAGIC,
duke@0 2607 "Incompatible magic value %u in class file %s",
duke@0 2608 magic, CHECK_(nullHandle));
duke@0 2609
duke@0 2610 // Version numbers
duke@0 2611 u2 minor_version = cfs->get_u2_fast();
duke@0 2612 u2 major_version = cfs->get_u2_fast();
duke@0 2613
duke@0 2614 // Check version numbers - we check this even with verifier off
duke@0 2615 if (!is_supported_version(major_version, minor_version)) {
duke@0 2616 if (name.is_null()) {
duke@0 2617 Exceptions::fthrow(
duke@0 2618 THREAD_AND_LOCATION,
duke@0 2619 vmSymbolHandles::java_lang_UnsupportedClassVersionError(),
duke@0 2620 "Unsupported major.minor version %u.%u",
duke@0 2621 major_version,
duke@0 2622 minor_version);
duke@0 2623 } else {
duke@0 2624 ResourceMark rm(THREAD);
duke@0 2625 Exceptions::fthrow(
duke@0 2626 THREAD_AND_LOCATION,
duke@0 2627 vmSymbolHandles::java_lang_UnsupportedClassVersionError(),
duke@0 2628 "%s : Unsupported major.minor version %u.%u",
duke@0 2629 name->as_C_string(),
duke@0 2630 major_version,
duke@0 2631 minor_version);
duke@0 2632 }
duke@0 2633 return nullHandle;
duke@0 2634 }
duke@0 2635
duke@0 2636 _major_version = major_version;
duke@0 2637 _minor_version = minor_version;
duke@0 2638
duke@0 2639
duke@0 2640 // Check if verification needs to be relaxed for this class file
duke@0 2641 // Do not restrict it to jdk1.0 or jdk1.1 to maintain backward compatibility (4982376)
duke@0 2642 _relax_verify = Verifier::relax_verify_for(class_loader());
duke@0 2643
duke@0 2644 // Constant pool
duke@0 2645 constantPoolHandle cp = parse_constant_pool(CHECK_(nullHandle));
duke@0 2646 int cp_size = cp->length();
duke@0 2647
duke@0 2648 cfs->guarantee_more(8, CHECK_(nullHandle)); // flags, this_class, super_class, infs_len
duke@0 2649
duke@0 2650 // Access flags
duke@0 2651 AccessFlags access_flags;
duke@0 2652 jint flags = cfs->get_u2_fast() & JVM_RECOGNIZED_CLASS_MODIFIERS;
duke@0 2653
duke@0 2654 if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
duke@0 2655 // Set abstract bit for old class files for backward compatibility
duke@0 2656 flags |= JVM_ACC_ABSTRACT;
duke@0 2657 }
duke@0 2658 verify_legal_class_modifiers(flags, CHECK_(nullHandle));
duke@0 2659 access_flags.set_flags(flags);
duke@0 2660
duke@0 2661 // This class and superclass
duke@0 2662 instanceKlassHandle super_klass;
duke@0 2663 u2 this_class_index = cfs->get_u2_fast();
duke@0 2664 check_property(
duke@0 2665 valid_cp_range(this_class_index, cp_size) &&
duke@0 2666 cp->tag_at(this_class_index).is_unresolved_klass(),
duke@0 2667 "Invalid this class index %u in constant pool in class file %s",
duke@0 2668 this_class_index, CHECK_(nullHandle));
duke@0 2669
duke@0 2670 symbolHandle class_name (THREAD, cp->unresolved_klass_at(this_class_index));
duke@0 2671 assert(class_name.not_null(), "class_name can't be null");
duke@0 2672
duke@0 2673 // It's important to set parsed_name *before* resolving the super class.
duke@0 2674 // (it's used for cleanup by the caller if parsing fails)
duke@0 2675 parsed_name = class_name;
duke@0 2676
duke@0 2677 // Update _class_name which could be null previously to be class_name
duke@0 2678 _class_name = class_name;
duke@0 2679
duke@0 2680 // Don't need to check whether this class name is legal or not.
duke@0 2681 // It has been checked when constant pool is parsed.
duke@0 2682 // However, make sure it is not an array type.
duke@0 2683 if (_need_verify) {
duke@0 2684 guarantee_property(class_name->byte_at(0) != JVM_SIGNATURE_ARRAY,
duke@0 2685 "Bad class name in class file %s",
duke@0 2686 CHECK_(nullHandle));
duke@0 2687 }
duke@0 2688
duke@0 2689 klassOop preserve_this_klass; // for storing result across HandleMark
duke@0 2690
duke@0 2691 // release all handles when parsing is done
duke@0 2692 { HandleMark hm(THREAD);
duke@0 2693
duke@0 2694 // Checks if name in class file matches requested name
duke@0 2695 if (name.not_null() && class_name() != name()) {
duke@0 2696 ResourceMark rm(THREAD);
duke@0 2697 Exceptions::fthrow(
duke@0 2698 THREAD_AND_LOCATION,
duke@0 2699 vmSymbolHandles::java_lang_NoClassDefFoundError(),
duke@0 2700 "%s (wrong name: %s)",
duke@0 2701 name->as_C_string(),
duke@0 2702 class_name->as_C_string()
duke@0 2703 );
duke@0 2704 return nullHandle;
duke@0 2705 }
duke@0 2706
duke@0 2707 if (TraceClassLoadingPreorder) {
duke@0 2708 tty->print("[Loading %s", name()->as_klass_external_name());
duke@0 2709 if (cfs->source() != NULL) tty->print(" from %s", cfs->source());
duke@0 2710 tty->print_cr("]");
duke@0 2711 }
duke@0 2712
duke@0 2713 u2 super_class_index = cfs->get_u2_fast();
duke@0 2714 if (super_class_index == 0) {
duke@0 2715 check_property(class_name() == vmSymbols::java_lang_Object(),
duke@0 2716 "Invalid superclass index %u in class file %s",
duke@0 2717 super_class_index,
duke@0 2718 CHECK_(nullHandle));
duke@0 2719 } else {
duke@0 2720 check_property(valid_cp_range(super_class_index, cp_size) &&
jrose@431 2721 is_klass_reference(cp, super_class_index),
duke@0 2722 "Invalid superclass index %u in class file %s",
duke@0 2723 super_class_index,
duke@0 2724 CHECK_(nullHandle));
duke@0 2725 // The class name should be legal because it is checked when parsing constant pool.
duke@0 2726 // However, make sure it is not an array type.
jrose@431 2727 bool is_array = false;
jrose@431 2728 if (cp->tag_at(super_class_index).is_klass()) {
jrose@431 2729 super_klass = instanceKlassHandle(THREAD, cp->resolved_klass_at(super_class_index));
jrose@431 2730 if (_need_verify)
jrose@431 2731 is_array = super_klass->oop_is_array();
jrose@431 2732 } else if (_need_verify) {
jrose@431 2733 is_array = (cp->unresolved_klass_at(super_class_index)->byte_at(0) == JVM_SIGNATURE_ARRAY);
jrose@431 2734 }
duke@0 2735 if (_need_verify) {
jrose@431 2736 guarantee_property(!is_array,
duke@0 2737 "Bad superclass name in class file %s", CHECK_(nullHandle));
duke@0 2738 }
duke@0 2739 }
duke@0 2740
duke@0 2741 // Interfaces
duke@0 2742 u2 itfs_len = cfs->get_u2_fast();
duke@0 2743 objArrayHandle local_interfaces;
duke@0 2744 if (itfs_len == 0) {
duke@0 2745 local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
duke@0 2746 } else {
mchung@875 2747 local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, CHECK_(nullHandle));
duke@0 2748 }
duke@0 2749
duke@0 2750 // Fields (offsets are filled in later)
duke@0 2751 struct FieldAllocationCount fac = {0,0,0,0,0,0,0,0,0,0};
duke@0 2752 objArrayHandle fields_annotations;
duke@0 2753 typeArrayHandle fields = parse_fields(cp, access_flags.is_interface(), &fac, &fields_annotations, CHECK_(nullHandle));
duke@0 2754 // Methods
duke@0 2755 bool has_final_method = false;
duke@0 2756 AccessFlags promoted_flags;
duke@0 2757 promoted_flags.set_flags(0);
duke@0 2758 // These need to be oop pointers because they are allocated lazily
duke@0 2759 // inside parse_methods inside a nested HandleMark
duke@0 2760 objArrayOop methods_annotations_oop = NULL;
duke@0 2761 objArrayOop methods_parameter_annotations_oop = NULL;
duke@0 2762 objArrayOop methods_default_annotations_oop = NULL;
duke@0 2763 objArrayHandle methods = parse_methods(cp, access_flags.is_interface(),
duke@0 2764 &promoted_flags,
duke@0 2765 &has_final_method,
duke@0 2766 &methods_annotations_oop,
duke@0 2767 &methods_parameter_annotations_oop,
duke@0 2768 &methods_default_annotations_oop,
duke@0 2769 CHECK_(nullHandle));
duke@0 2770
duke@0 2771 objArrayHandle methods_annotations(THREAD, methods_annotations_oop);
duke@0 2772 objArrayHandle methods_parameter_annotations(THREAD, methods_parameter_annotations_oop);
duke@0 2773 objArrayHandle methods_default_annotations(THREAD, methods_default_annotations_oop);
duke@0 2774
duke@0 2775 // We check super class after class file is parsed and format is checked
jrose@431 2776 if (super_class_index > 0 && super_klass.is_null()) {
duke@0 2777 symbolHandle sk (THREAD, cp->klass_name_at(super_class_index));
duke@0 2778 if (access_flags.is_interface()) {
duke@0 2779 // Before attempting to resolve the superclass, check for class format
duke@0 2780 // errors not checked yet.
duke@0 2781 guarantee_property(sk() == vmSymbols::java_lang_Object(),
duke@0 2782 "Interfaces must have java.lang.Object as superclass in class file %s",
duke@0 2783 CHECK_(nullHandle));
duke@0 2784 }
duke@0 2785 klassOop k = SystemDictionary::resolve_super_or_fail(class_name,
duke@0 2786 sk,
duke@0 2787 class_loader,
duke@0 2788 protection_domain,
duke@0 2789 true,
duke@0 2790 CHECK_(nullHandle));
mchung@875 2791
duke@0 2792 KlassHandle kh (THREAD, k);
duke@0 2793 super_klass = instanceKlassHandle(THREAD, kh());
jrose@474 2794 if (LinkWellKnownClasses) // my super class is well known to me
jrose@474 2795 cp->klass_at_put(super_class_index, super_klass()); // eagerly resolve
jrose@431 2796 }
jrose@431 2797 if (super_klass.not_null()) {
duke@0 2798 if (super_klass->is_interface()) {
duke@0 2799 ResourceMark rm(THREAD);
duke@0 2800 Exceptions::fthrow(
duke@0 2801 THREAD_AND_LOCATION,
duke@0 2802 vmSymbolHandles::java_lang_IncompatibleClassChangeError(),
duke@0 2803 "class %s has interface %s as super class",
duke@0 2804 class_name->as_klass_external_name(),
duke@0 2805 super_klass->external_name()
duke@0 2806 );
duke@0 2807 return nullHandle;
duke@0 2808 }
duke@0 2809 // Make sure super class is not final
duke@0 2810 if (super_klass->is_final()) {
duke@0 2811 THROW_MSG_(vmSymbols::java_lang_VerifyError(), "Cannot inherit from final class", nullHandle);
duke@0 2812 }
duke@0 2813 }
duke@0 2814
duke@0 2815 // Compute the transitive list of all unique interfaces implemented by this class
duke@0 2816 objArrayHandle transitive_interfaces = compute_transitive_interfaces(super_klass, local_interfaces, CHECK_(nullHandle));
duke@0 2817
duke@0 2818 // sort methods
duke@0 2819 typeArrayHandle method_ordering = sort_methods(methods,
duke@0 2820 methods_annotations,
duke@0 2821 methods_parameter_annotations,
duke@0 2822 methods_default_annotations,
duke@0 2823 CHECK_(nullHandle));
duke@0 2824
duke@0 2825 // promote flags from parse_methods() to the klass' flags
duke@0 2826 access_flags.add_promoted_flags(promoted_flags.as_int());
duke@0 2827
duke@0 2828 // Size of Java vtable (in words)
duke@0 2829 int vtable_size = 0;
duke@0 2830 int itable_size = 0;
duke@0 2831 int num_miranda_methods = 0;
duke@0 2832
duke@0 2833 klassVtable::compute_vtable_size_and_num_mirandas(vtable_size,
duke@0 2834 num_miranda_methods,
duke@0 2835 super_klass(),
duke@0 2836 methods(),
duke@0 2837 access_flags,
acorn@652 2838 class_loader,
acorn@652 2839 class_name,
acorn@652 2840 local_interfaces(),
acorn@652 2841 CHECK_(nullHandle));
duke@0 2842
duke@0 2843 // Size of Java itable (in words)
duke@0 2844 itable_size = access_flags.is_interface() ? 0 : klassItable::compute_itable_size(transitive_interfaces);
duke@0 2845
duke@0 2846 // Field size and offset computation
duke@0 2847 int nonstatic_field_size = super_klass() == NULL ? 0 : super_klass->nonstatic_field_size();
duke@0 2848 #ifndef PRODUCT
duke@0 2849 int orig_nonstatic_field_size = 0;
duke@0 2850 #endif
duke@0 2851 int static_field_size = 0;
duke@0 2852 int next_static_oop_offset;
duke@0 2853 int next_static_double_offset;
duke@0 2854 int next_static_word_offset;
duke@0 2855 int next_static_short_offset;
duke@0 2856 int next_static_byte_offset;
duke@0 2857 int next_static_type_offset;
duke@0 2858 int next_nonstatic_oop_offset;
duke@0 2859 int next_nonstatic_double_offset;
duke@0 2860 int next_nonstatic_word_offset;
duke@0 2861 int next_nonstatic_short_offset;
duke@0 2862 int next_nonstatic_byte_offset;
duke@0 2863 int next_nonstatic_type_offset;
duke@0 2864 int first_nonstatic_oop_offset;
duke@0 2865 int first_nonstatic_field_offset;
duke@0 2866 int next_nonstatic_field_offset;
duke@0 2867
duke@0 2868 // Calculate the starting byte offsets
duke@0 2869 next_static_oop_offset = (instanceKlass::header_size() +
duke@0 2870 align_object_offset(vtable_size) +
duke@0 2871 align_object_offset(itable_size)) * wordSize;
duke@0 2872 next_static_double_offset = next_static_oop_offset +
coleenp@113 2873 (fac.static_oop_count * heapOopSize);
duke@0 2874 if ( fac.static_double_count &&
duke@0 2875 (Universe::field_type_should_be_aligned(T_DOUBLE) ||
duke@0 2876 Universe::field_type_should_be_aligned(T_LONG)) ) {
duke@0 2877 next_static_double_offset = align_size_up(next_static_double_offset, BytesPerLong);
duke@0 2878 }
duke@0 2879
duke@0 2880 next_static_word_offset = next_static_double_offset +
duke@0 2881 (fac.static_double_count * BytesPerLong);
duke@0 2882 next_static_short_offset = next_static_word_offset +
duke@0 2883 (fac.static_word_count * BytesPerInt);
duke@0 2884 next_static_byte_offset = next_static_short_offset +
duke@0 2885 (fac.static_short_count * BytesPerShort);
duke@0 2886 next_static_type_offset = align_size_up((next_static_byte_offset +
duke@0 2887 fac.static_byte_count ), wordSize );
duke@0 2888 static_field_size = (next_static_type_offset -
duke@0 2889 next_static_oop_offset) / wordSize;
kvn@165 2890 first_nonstatic_field_offset = instanceOopDesc::base_offset_in_bytes() +
kvn@165 2891 nonstatic_field_size * heapOopSize;
duke@0 2892 next_nonstatic_field_offset = first_nonstatic_field_offset;
duke@0 2893
duke@0 2894 // Add fake fields for java.lang.Class instances (also see below)
duke@0 2895 if (class_name() == vmSymbols::java_lang_Class() && class_loader.is_null()) {
duke@0 2896 java_lang_Class_fix_pre(&methods, &fac, CHECK_(nullHandle));
duke@0 2897 }
duke@0 2898
jrose@710 2899 // adjust the vmentry field declaration in java.dyn.MethodHandle
jrose@710 2900 if (EnableMethodHandles && class_name() == vmSymbols::sun_dyn_MethodHandleImpl() && class_loader.is_null()) {
jrose@710 2901 java_dyn_MethodHandle_fix_pre(cp, &fields, &fac, CHECK_(nullHandle));
jrose@710 2902 }
jrose@710 2903
duke@0 2904 // Add a fake "discovered" field if it is not present
duke@0 2905 // for compatibility with earlier jdk's.
duke@0 2906 if (class_name() == vmSymbols::java_lang_ref_Reference()
duke@0 2907 && class_loader.is_null()) {
duke@0 2908 java_lang_ref_Reference_fix_pre(&fields, cp, &fac, CHECK_(nullHandle));
duke@0 2909 }
duke@0 2910 // end of "discovered" field compactibility fix
duke@0 2911
jcoomes@939 2912 unsigned int nonstatic_double_count = fac.nonstatic_double_count;
jcoomes@939 2913 unsigned int nonstatic_word_count = fac.nonstatic_word_count;
jcoomes@939 2914 unsigned int nonstatic_short_count = fac.nonstatic_short_count;
jcoomes@939 2915 unsigned int nonstatic_byte_count = fac.nonstatic_byte_count;
jcoomes@939 2916 unsigned int nonstatic_oop_count = fac.nonstatic_oop_count;
duke@0 2917
coleenp@113 2918 bool super_has_nonstatic_fields =
coleenp@113 2919 (super_klass() != NULL && super_klass->has_nonstatic_fields());
coleenp@113 2920 bool has_nonstatic_fields = super_has_nonstatic_fields ||
coleenp@113 2921 ((nonstatic_double_count + nonstatic_word_count +
coleenp@113 2922 nonstatic_short_count + nonstatic_byte_count +
coleenp@113 2923 nonstatic_oop_count) != 0);
coleenp@113 2924
coleenp@113 2925
jcoomes@939 2926 // Prepare list of oops for oop map generation.
jcoomes@939 2927 int* nonstatic_oop_offsets;
jcoomes@939 2928 unsigned int* nonstatic_oop_counts;
jcoomes@939 2929 unsigned int nonstatic_oop_map_count = 0;
duke@0 2930
duke@0 2931 nonstatic_oop_offsets = NEW_RESOURCE_ARRAY_IN_THREAD(
jcoomes@939 2932 THREAD, int, nonstatic_oop_count + 1);
jcoomes@938 2933 nonstatic_oop_counts = NEW_RESOURCE_ARRAY_IN_THREAD(
jcoomes@939 2934 THREAD, unsigned int, nonstatic_oop_count + 1);
duke@0 2935
duke@0 2936 // Add fake fields for java.lang.Class instances (also see above).
duke@0 2937 // FieldsAllocationStyle and CompactFields values will be reset to default.
duke@0 2938 if(class_name() == vmSymbols::java_lang_Class() && class_loader.is_null()) {
duke@0 2939 java_lang_Class_fix_post(&next_nonstatic_field_offset);
jcoomes@939 2940 nonstatic_oop_offsets[0] = first_nonstatic_field_offset;
jcoomes@939 2941 const uint fake_oop_count = (next_nonstatic_field_offset -
jcoomes@939 2942 first_nonstatic_field_offset) / heapOopSize;
jcoomes@939 2943 nonstatic_oop_counts[0] = fake_oop_count;
jcoomes@939 2944 nonstatic_oop_map_count = 1;
jcoomes@939 2945 nonstatic_oop_count -= fake_oop_count;
duke@0 2946 first_nonstatic_oop_offset = first_nonstatic_field_offset;
duke@0 2947 } else {
duke@0 2948 first_nonstatic_oop_offset = 0; // will be set for first oop field
duke@0 2949 }
duke@0 2950
duke@0 2951 #ifndef PRODUCT
duke@0 2952 if( PrintCompactFieldsSavings ) {
duke@0 2953 next_nonstatic_double_offset = next_nonstatic_field_offset +
coleenp@113 2954 (nonstatic_oop_count * heapOopSize);
duke@0 2955 if ( nonstatic_double_count > 0 ) {
duke@0 2956 next_nonstatic_double_offset = align_size_up(next_nonstatic_double_offset, BytesPerLong);
duke@0 2957 }
duke@0 2958 next_nonstatic_word_offset = next_nonstatic_double_offset +
duke@0 2959 (nonstatic_double_count * BytesPerLong);
duke@0 2960 next_nonstatic_short_offset = next_nonstatic_word_offset +
duke@0 2961 (nonstatic_word_count * BytesPerInt);
duke@0 2962 next_nonstatic_byte_offset = next_nonstatic_short_offset +
duke@0 2963 (nonstatic_short_count * BytesPerShort);
duke@0 2964 next_nonstatic_type_offset = align_size_up((next_nonstatic_byte_offset +
kvn@165 2965 nonstatic_byte_count ), heapOopSize );
duke@0 2966 orig_nonstatic_field_size = nonstatic_field_size +
kvn@165 2967 ((next_nonstatic_type_offset - first_nonstatic_field_offset)/heapOopSize);
duke@0 2968 }
duke@0 2969 #endif
duke@0 2970 bool compact_fields = CompactFields;
duke@0 2971 int allocation_style = FieldsAllocationStyle;
duke@0 2972 if( allocation_style < 0 || allocation_style > 1 ) { // Out of range?
duke@0 2973 assert(false, "0 <= FieldsAllocationStyle <= 1");
duke@0 2974 allocation_style = 1; // Optimistic
duke@0 2975 }
duke@0 2976
duke@0 2977 // The next classes have predefined hard-coded fields offsets
duke@0 2978 // (see in JavaClasses::compute_hard_coded_offsets()).
duke@0 2979 // Use default fields allocation order for them.
duke@0 2980 if( (allocation_style != 0 || compact_fields ) && class_loader.is_null() &&
duke@0 2981 (class_name() == vmSymbols::java_lang_AssertionStatusDirectives() ||
duke@0 2982 class_name() == vmSymbols::java_lang_Class() ||
duke@0 2983 class_name() == vmSymbols::java_lang_ClassLoader() ||
duke@0 2984 class_name() == vmSymbols::java_lang_ref_Reference() ||
duke@0 2985 class_name() == vmSymbols::java_lang_ref_SoftReference() ||
duke@0 2986 class_name() == vmSymbols::java_lang_StackTraceElement() ||
duke@0 2987 class_name() == vmSymbols::java_lang_String() ||
coleenp@113 2988 class_name() == vmSymbols::java_lang_Throwable() ||
coleenp@113 2989 class_name() == vmSymbols::java_lang_Boolean() ||
coleenp@113 2990 class_name() == vmSymbols::java_lang_Character() ||
coleenp@113 2991 class_name() == vmSymbols::java_lang_Float() ||
coleenp@113 2992 class_name() == vmSymbols::java_lang_Double() ||
coleenp@113 2993 class_name() == vmSymbols::java_lang_Byte() ||
coleenp@113 2994 class_name() == vmSymbols::java_lang_Short() ||
coleenp@113 2995 class_name() == vmSymbols::java_lang_Integer() ||
coleenp@113 2996 class_name() == vmSymbols::java_lang_Long())) {
duke@0 2997 allocation_style = 0; // Allocate oops first
duke@0 2998 compact_fields = false; // Don't compact fields
duke@0 2999 }
duke@0 3000
duke@0 3001 if( allocation_style == 0 ) {
duke@0 3002 // Fields order: oops, longs/doubles, ints, shorts/chars, bytes
duke@0 3003 next_nonstatic_oop_offset = next_nonstatic_field_offset;
duke@0 3004 next_nonstatic_double_offset = next_nonstatic_oop_offset +
coleenp@113 3005 (nonstatic_oop_count * heapOopSize);
duke@0 3006 } else if( allocation_style == 1 ) {
duke@0 3007 // Fields order: longs/doubles, ints, shorts/chars, bytes, oops
duke@0 3008 next_nonstatic_double_offset = next_nonstatic_field_offset;
duke@0 3009 } else {
duke@0 3010 ShouldNotReachHere();
duke@0 3011 }
duke@0 3012
duke@0 3013 int nonstatic_oop_space_count = 0;
duke@0 3014 int nonstatic_word_space_count = 0;
duke@0 3015 int nonstatic_short_space_count = 0;
duke@0 3016 int nonstatic_byte_space_count = 0;
duke@0 3017 int nonstatic_oop_space_offset;
duke@0 3018 int nonstatic_word_space_offset;
duke@0 3019 int nonstatic_short_space_offset;
duke@0 3020 int nonstatic_byte_space_offset;
duke@0 3021
kvn@165 3022 if( nonstatic_double_count > 0 ) {
kvn@165 3023 int offset = next_nonstatic_double_offset;
duke@0 3024 next_nonstatic_double_offset = align_size_up(offset, BytesPerLong);
duke@0 3025 if( compact_fields && offset != next_nonstatic_double_offset ) {
duke@0 3026 // Allocate available fields into the gap before double field.
duke@0 3027 int length = next_nonstatic_double_offset - offset;
duke@0 3028 assert(length == BytesPerInt, "");
duke@0 3029 nonstatic_word_space_offset = offset;
duke@0 3030 if( nonstatic_word_count > 0 ) {
duke@0 3031 nonstatic_word_count -= 1;
duke@0 3032 nonstatic_word_space_count = 1; // Only one will fit
duke@0 3033 length -= BytesPerInt;
duke@0 3034 offset += BytesPerInt;
duke@0 3035 }
duke@0 3036 nonstatic_short_space_offset = offset;
duke@0 3037 while( length >= BytesPerShort && nonstatic_short_count > 0 ) {
duke@0 3038 nonstatic_short_count -= 1;
duke@0 3039 nonstatic_short_space_count += 1;
duke@0 3040 length -= BytesPerShort;
duke@0 3041 offset += BytesPerShort;
duke@0 3042 }
duke@0 3043 nonstatic_byte_space_offset = offset;
duke@0 3044 while( length > 0 && nonstatic_byte_count > 0 ) {
duke@0 3045 nonstatic_byte_count -= 1;
duke@0 3046 nonstatic_byte_space_count += 1;
duke@0 3047 length -= 1;
duke@0 3048 }
duke@0 3049 // Allocate oop field in the gap if there are no other fields for that.
duke@0 3050 nonstatic_oop_space_offset = offset;
kvn@165 3051 if( length >= heapOopSize && nonstatic_oop_count > 0 &&
duke@0 3052 allocation_style != 0 ) { // when oop fields not first
duke@0 3053 nonstatic_oop_count -= 1;
duke@0 3054 nonstatic_oop_space_count = 1; // Only one will fit
coleenp@113 3055 length -= heapOopSize;
coleenp@113 3056 offset += heapOopSize;
duke@0 3057 }
duke@0 3058 }
duke@0 3059 }
duke@0 3060
duke@0 3061 next_nonstatic_word_offset = next_nonstatic_double_offset +
duke@0 3062 (nonstatic_double_count * BytesPerLong);
duke@0 3063 next_nonstatic_short_offset = next_nonstatic_word_offset +
duke@0 3064 (nonstatic_word_count * BytesPerInt);
duke@0 3065 next_nonstatic_byte_offset = next_nonstatic_short_offset +
duke@0 3066 (nonstatic_short_count * BytesPerShort);
duke@0 3067
duke@0 3068 int notaligned_offset;
duke@0 3069 if( allocation_style == 0 ) {
duke@0 3070 notaligned_offset = next_nonstatic_byte_offset + nonstatic_byte_count;
duke@0 3071 } else { // allocation_style == 1
duke@0 3072 next_nonstatic_oop_offset = next_nonstatic_byte_offset + nonstatic_byte_count;
duke@0 3073 if( nonstatic_oop_count > 0 ) {
coleenp@113 3074 next_nonstatic_oop_offset = align_size_up(next_nonstatic_oop_offset, heapOopSize);
duke@0 3075 }
coleenp@113 3076 notaligned_offset = next_nonstatic_oop_offset + (nonstatic_oop_count * heapOopSize);
duke@0 3077 }
kvn@165 3078 next_nonstatic_type_offset = align_size_up(notaligned_offset, heapOopSize );
duke@0 3079 nonstatic_field_size = nonstatic_field_size + ((next_nonstatic_type_offset
kvn@165 3080 - first_nonstatic_field_offset)/heapOopSize);
duke@0 3081
duke@0 3082 // Iterate over fields again and compute correct offsets.
duke@0 3083 // The field allocation type was temporarily stored in the offset slot.
duke@0 3084 // oop fields are located before non-oop fields (static and non-static).
duke@0 3085 int len = fields->length();
duke@0 3086 for (int i = 0; i < len; i += instanceKlass::next_offset) {
duke@0 3087 int real_offset;
duke@0 3088 FieldAllocationType atype = (FieldAllocationType) fields->ushort_at(i+4);
duke@0 3089 switch (atype) {
duke@0 3090 case STATIC_OOP:
duke@0 3091 real_offset = next_static_oop_offset;
coleenp@113 3092 next_static_oop_offset += heapOopSize;
duke@0 3093 break;
duke@0 3094 case STATIC_BYTE:
duke@0 3095 real_offset = next_static_byte_offset;
duke@0 3096 next_static_byte_offset += 1;
duke@0 3097 break;
duke@0 3098 case STATIC_SHORT:
duke@0 3099 real_offset = next_static_short_offset;
duke@0 3100 next_static_short_offset += BytesPerShort;
duke@0 3101 break;
duke@0 3102 case STATIC_WORD:
duke@0 3103 real_offset = next_static_word_offset;
duke@0 3104 next_static_word_offset += BytesPerInt;
duke@0 3105 break;
duke@0 3106 case STATIC_ALIGNED_DOUBLE:
duke@0 3107 case STATIC_DOUBLE:
duke@0 3108 real_offset = next_static_double_offset;
duke@0 3109 next_static_double_offset += BytesPerLong;
duke@0 3110 break;
duke@0 3111 case NONSTATIC_OOP:
duke@0 3112 if( nonstatic_oop_space_count > 0 ) {
duke@0 3113 real_offset = nonstatic_oop_space_offset;
coleenp@113 3114 nonstatic_oop_space_offset += heapOopSize;
duke@0 3115 nonstatic_oop_space_count -= 1;
duke@0 3116 } else {
duke@0 3117 real_offset = next_nonstatic_oop_offset;
coleenp@113 3118 next_nonstatic_oop_offset += heapOopSize;
duke@0 3119 }
duke@0 3120 // Update oop maps
duke@0 3121 if( nonstatic_oop_map_count > 0 &&
duke@0 3122 nonstatic_oop_offsets[nonstatic_oop_map_count - 1] ==
jcoomes@939 3123 real_offset -
jcoomes@939 3124 int(nonstatic_oop_counts[nonstatic_oop_map_count - 1]) *
jcoomes@939 3125 heapOopSize ) {
duke@0 3126 // Extend current oop map
jcoomes@938 3127 nonstatic_oop_counts[nonstatic_oop_map_count - 1] += 1;
duke@0 3128 } else {
duke@0 3129 // Create new oop map
jcoomes@939 3130 nonstatic_oop_offsets[nonstatic_oop_map_count] = real_offset;
jcoomes@938 3131 nonstatic_oop_counts [nonstatic_oop_map_count] = 1;
duke@0 3132 nonstatic_oop_map_count += 1;
duke@0 3133 if( first_nonstatic_oop_offset == 0 ) { // Undefined
duke@0 3134 first_nonstatic_oop_offset = real_offset;
duke@0 3135 }
duke@0 3136 }
duke@0 3137 break;
duke@0 3138 case NONSTATIC_BYTE:
duke@0 3139 if( nonstatic_byte_space_count > 0 ) {
duke@0 3140 real_offset = nonstatic_byte_space_offset;
duke@0 3141 nonstatic_byte_space_offset += 1;
duke@0 3142 nonstatic_byte_space_count -= 1;
duke@0 3143 } else {
duke@0 3144 real_offset = next_nonstatic_byte_offset;
duke@0 3145 next_nonstatic_byte_offset += 1;
duke@0 3146 }
duke@0 3147 break;
duke@0 3148 case NONSTATIC_SHORT:
duke@0 3149 if( nonstatic_short_space_count > 0 ) {
duke@0 3150 real_offset = nonstatic_short_space_offset;
duke@0 3151 nonstatic_short_space_offset += BytesPerShort;
duke@0 3152 nonstatic_short_space_count -= 1;
duke@0 3153 } else {
duke@0 3154 real_offset = next_nonstatic_short_offset;
duke@0 3155 next_nonstatic_short_offset += BytesPerShort;
duke@0 3156 }
duke@0 3157 break;
duke@0 3158 case NONSTATIC_WORD:
duke@0 3159 if( nonstatic_word_space_count > 0 ) {
duke@0 3160 real_offset = nonstatic_word_space_offset;
duke@0 3161 nonstatic_word_space_offset += BytesPerInt;
duke@0 3162 nonstatic_word_space_count -= 1;
duke@0 3163 } else {
duke@0 3164 real_offset = next_nonstatic_word_offset;
duke@0 3165 next_nonstatic_word_offset += BytesPerInt;
duke@0 3166 }
duke@0 3167 break;
duke@0 3168 case NONSTATIC_ALIGNED_DOUBLE:
duke@0 3169 case NONSTATIC_DOUBLE:
duke@0 3170 real_offset = next_nonstatic_double_offset;
duke@0 3171 next_nonstatic_double_offset += BytesPerLong;
duke@0 3172 break;
duke@0 3173 default:
duke@0 3174 ShouldNotReachHere();
duke@0 3175 }
duke@0 3176 fields->short_at_put(i+4, extract_low_short_from_int(real_offset) );
duke@0 3177 fields->short_at_put(i+5, extract_high_short_from_int(real_offset) );
duke@0 3178 }
duke@0 3179
duke@0 3180 // Size of instances
duke@0 3181 int instance_size;
duke@0 3182
kvn@165 3183 next_nonstatic_type_offset = align_size_up(notaligned_offset, wordSize );
duke@0 3184 instance_size = align_object_size(next_nonstatic_type_offset / wordSize);
duke@0 3185
kvn@165 3186 assert(instance_size == align_object_size(align_size_up((instanceOopDesc::base_offset_in_bytes() + nonstatic_field_size*heapOopSize), wordSize) / wordSize), "consistent layout helper value");
duke@0 3187
jcoomes@938 3188 // Number of non-static oop map blocks allocated at end of klass.
jcoomes@939 3189 const unsigned int total_oop_map_count =
jcoomes@939 3190 compute_oop_map_count(super_klass, nonstatic_oop_map_count,
jcoomes@939 3191 first_nonstatic_oop_offset);
duke@0 3192
duke@0 3193 // Compute reference type
duke@0 3194 ReferenceType rt;
duke@0 3195 if (super_klass() == NULL) {
duke@0 3196 rt = REF_NONE;
duke@0 3197 } else {
duke@0 3198 rt = super_klass->reference_type();
duke@0 3199 }
duke@0 3200
duke@0 3201 // We can now create the basic klassOop for this klass
jcoomes@939 3202 klassOop ik = oopFactory::new_instanceKlass(vtable_size, itable_size,
jcoomes@939 3203 static_field_size,
jcoomes@939 3204 total_oop_map_count,
jcoomes@939 3205 rt, CHECK_(nullHandle));
duke@0 3206 instanceKlassHandle this_klass (THREAD, ik);
duke@0 3207
jcoomes@938 3208 assert(this_klass->static_field_size() == static_field_size, "sanity");
jcoomes@938 3209 assert(this_klass->nonstatic_oop_map_count() == total_oop_map_count,
jcoomes@938 3210 "sanity");
duke@0 3211
duke@0 3212 // Fill in information already parsed
duke@0 3213 this_klass->set_access_flags(access_flags);
acorn@975 3214 this_klass->set_should_verify_class(verify);
duke@0 3215 jint lh = Klass::instance_layout_helper(instance_size, false);
duke@0 3216 this_klass->set_layout_helper(lh);
duke@0 3217 assert(this_klass->oop_is_instance(), "layout is correct");
duke@0 3218 assert(this_klass->size_helper() == instance_size, "correct size_helper");
duke@0 3219 // Not yet: supers are done below to support the new subtype-checking fields
duke@0 3220 //this_klass->set_super(super_klass());
duke@0 3221 this_klass->set_class_loader(class_loader());
duke@0 3222 this_klass->set_nonstatic_field_size(nonstatic_field_size);
acorn@975 3223 this_klass->set_has_nonstatic_fields(has_nonstatic_fields);
duke@0 3224 this_klass->set_static_oop_field_size(fac.static_oop_count);
duke@0 3225 cp->set_pool_holder(this_klass());
duke@0 3226 this_klass->set_constants(cp());
duke@0 3227 this_klass->set_local_interfaces(local_interfaces());
duke@0 3228 this_klass->set_fields(fields());
duke@0 3229 this_klass->set_methods(methods());
duke@0 3230 if (has_final_method) {
duke@0 3231 this_klass->set_has_final_method();
duke@0 3232 }
duke@0 3233 this_klass->set_method_ordering(method_ordering());
duke@0 3234 this_klass->set_initial_method_idnum(methods->length());
duke@0 3235 this_klass->set_name(cp->klass_name_at(this_class_index));
jrose@710 3236 if (LinkWellKnownClasses || is_anonymous()) // I am well known to myself
jrose@474 3237 cp->klass_at_put(this_class_index, this_klass()); // eagerly resolve
duke@0 3238 this_klass->set_protection_domain(protection_domain());
duke@0 3239 this_klass->set_fields_annotations(fields_annotations());
duke@0 3240 this_klass->set_methods_annotations(methods_annotations());
duke@0 3241 this_klass->set_methods_parameter_annotations(methods_parameter_annotations());
duke@0 3242 this_klass->set_methods_default_annotations(methods_default_annotations());
duke@0 3243
duke@0 3244 this_klass->set_minor_version(minor_version);
duke@0 3245 this_klass->set_major_version(major_version);
duke@0 3246
jrose@856 3247 // Set up methodOop::intrinsic_id as soon as we know the names of methods.
jrose@856 3248 // (We used to do this lazily, but now we query it in Rewriter,
jrose@856 3249 // which is eagerly done for every method, so we might as well do it now,
jrose@856 3250 // when everything is fresh in memory.)
jrose@856 3251 if (methodOopDesc::klass_id_for_intrinsics(this_klass->as_klassOop()) != vmSymbols::NO_SID) {
jrose@856 3252 for (int j = 0; j < methods->length(); j++) {
jrose@856 3253 ((methodOop)methods->obj_at(j))->init_intrinsic_id();
jrose@856 3254 }
jrose@856 3255 }
jrose@856 3256
duke@0 3257 if (cached_class_file_bytes != NULL) {
duke@0 3258 // JVMTI: we have an instanceKlass now, tell it about the cached bytes
duke@0 3259 this_klass->set_cached_class_file(cached_class_file_bytes,
duke@0 3260 cached_class_file_length);
duke@0 3261 }
duke@0 3262
duke@0 3263 // Miranda methods
duke@0 3264 if ((num_miranda_methods > 0) ||
duke@0 3265 // if this class introduced new miranda methods or
duke@0 3266 (super_klass.not_null() && (super_klass->has_miranda_methods()))
duke@0 3267 // super class exists and this class inherited miranda methods
duke@0 3268 ) {
duke@0 3269 this_klass->set_has_miranda_methods(); // then set a flag
duke@0 3270 }
duke@0 3271
duke@0 3272 // Additional attributes
duke@0 3273 parse_classfile_attributes(cp, this_klass, CHECK_(nullHandle));
duke@0 3274
duke@0 3275 // Make sure this is the end of class file stream
duke@0 3276 guarantee_property(cfs->at_eos(), "Extra bytes at the end of class file %s", CHECK_(nullHandle));
duke@0 3277
duke@0 3278 // Initialize static fields
duke@0 3279 this_klass->do_local_static_fields(&initialize_static_field, CHECK_(nullHandle));
duke@0 3280
duke@0 3281 // VerifyOops believes that once this has been set, the object is completely loaded.
duke@0 3282 // Compute transitive closure of interfaces this class implements
duke@0 3283 this_klass->set_transitive_interfaces(transitive_interfaces());
duke@0 3284
duke@0 3285 // Fill in information needed to compute superclasses.
duke@0 3286 this_klass->initialize_supers(super_klass(), CHECK_(nullHandle));
duke@0 3287
duke@0 3288 // Initialize itable offset tables
duke@0 3289 klassItable::setup_itable_offset_table(this_klass);
duke@0 3290
duke@0 3291 // Do final class setup
jcoomes@938 3292 fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_counts);
duke@0 3293
duke@0 3294 set_precomputed_flags(this_klass);
duke@0 3295
duke@0 3296 // reinitialize modifiers, using the InnerClasses attribute
duke@0 3297 int computed_modifiers = this_klass->compute_modifier_flags(CHECK_(nullHandle));
duke@0 3298 this_klass->set_modifier_flags(computed_modifiers);
duke@0 3299
duke@0 3300 // check if this class can access its super class
duke@0 3301 check_super_class_access(this_klass, CHECK_(nullHandle));
duke@0 3302
duke@0 3303 // check if this class can access its superinterfaces
duke@0 3304 check_super_interface_access(this_klass, CHECK_(nullHandle));
duke@0 3305
duke@0 3306 // check if this class overrides any final method
duke@0 3307 check_final_method_override(this_klass, CHECK_(nullHandle));
duke@0 3308
duke@0 3309 // check that if this class is an interface then it doesn't have static methods
duke@0 3310 if (this_klass->is_interface()) {
duke@0 3311 check_illegal_static_method(this_klass, CHECK_(nullHandle));
duke@0 3312 }
duke@0 3313
duke@0 3314 ClassLoadingService::notify_class_loaded(instanceKlass::cast(this_klass()),
duke@0 3315 false /* not shared class */);
duke@0 3316
duke@0 3317 if (TraceClassLoading) {
duke@0 3318 // print in a single call to reduce interleaving of output
duke@0 3319 if (cfs->source() != NULL) {
duke@0 3320 tty->print("[Loaded %s from %s]\n", this_klass->external_name(),
duke@0 3321 cfs->source());
duke@0 3322 } else if (class_loader.is_null()) {
duke@0 3323 if (THREAD->is_Java_thread()) {
duke@0 3324 klassOop caller = ((JavaThread*)THREAD)->security_get_caller_class(1);
duke@0 3325 tty->print("[Loaded %s by instance of %s]\n",
duke@0 3326 this_klass->external_name(),
duke@0 3327 instanceKlass::cast(caller)->external_name());
duke@0 3328 } else {
duke@0 3329 tty->print("[Loaded %s]\n", this_klass->external_name());
duke@0 3330 }
duke@0 3331 } else {
duke@0 3332 ResourceMark rm;
duke@0 3333 tty->print("[Loaded %s from %s]\n", this_klass->external_name(),
duke@0 3334 instanceKlass::cast(class_loader->klass())->external_name());
duke@0 3335 }
duke@0 3336 }
duke@0 3337
duke@0 3338 if (TraceClassResolution) {
duke@0 3339 // print out the superclass.
duke@0 3340 const char * from = Klass::cast(this_klass())->external_name();
duke@0 3341 if (this_klass->java_super() != NULL) {
acorn@657 3342 tty->print("RESOLVE %s %s (super)\n", from, instanceKlass::cast(this_klass->java_super())->external_name());
duke@0 3343 }
duke@0 3344 // print out each of the interface classes referred to by this class.
duke@0 3345 objArrayHandle local_interfaces(THREAD, this_klass->local_interfaces());
duke@0 3346 if (!local_interfaces.is_null()) {
duke@0 3347 int length = local_interfaces->length();
duke@0 3348 for (int i = 0; i < length; i++) {
duke@0 3349 klassOop k = klassOop(local_interfaces->obj_at(i));
duke@0 3350 instanceKlass* to_class = instanceKlass::cast(k);
duke@0 3351 const char * to = to_class->external_name();
acorn@657 3352 tty->print("RESOLVE %s %s (interface)\n", from, to);
duke@0 3353 }
duke@0 3354 }
duke@0 3355 }
duke@0 3356
duke@0 3357 #ifndef PRODUCT
duke@0 3358 if( PrintCompactFieldsSavings ) {
duke@0 3359 if( nonstatic_field_size < orig_nonstatic_field_size ) {
kvn@165 3360 tty->print("[Saved %d of %d bytes in %s]\n",
kvn@165 3361 (orig_nonstatic_field_size - nonstatic_field_size)*heapOopSize,
kvn@165 3362 orig_nonstatic_field_size*heapOopSize,
kvn@165 3363 this_klass->external_name());
duke@0 3364 } else if( nonstatic_field_size > orig_nonstatic_field_size ) {
kvn@165 3365 tty->print("[Wasted %d over %d bytes in %s]\n",
kvn@165 3366 (nonstatic_field_size - orig_nonstatic_field_size)*heapOopSize,
kvn@165 3367 orig_nonstatic_field_size*heapOopSize,
kvn@165 3368 this_klass->external_name());
duke@0 3369 }
duke@0 3370 }
duke@0 3371 #endif
duke@0 3372
duke@0 3373 // preserve result across HandleMark
duke@0 3374 preserve_this_klass = this_klass();
duke@0 3375 }
duke@0 3376
duke@0 3377 // Create new handle outside HandleMark
duke@0 3378 instanceKlassHandle this_klass (THREAD, preserve_this_klass);
duke@0 3379 debug_only(this_klass->as_klassOop()->verify();)
duke@0 3380
duke@0 3381 return this_klass;
duke@0 3382 }
duke@0 3383
duke@0 3384
jcoomes@939 3385 unsigned int
jcoomes@939 3386 ClassFileParser::compute_oop_map_count(instanceKlassHandle super,
jcoomes@939 3387 unsigned int nonstatic_oop_map_count,
jcoomes@939 3388 int first_nonstatic_oop_offset) {
jcoomes@939 3389 unsigned int map_count =
jcoomes@939 3390 super.is_null() ? 0 : super->nonstatic_oop_map_count();
duke@0 3391 if (nonstatic_oop_map_count > 0) {
duke@0 3392 // We have oops to add to map
jcoomes@938 3393 if (map_count == 0) {
jcoomes@938 3394 map_count = nonstatic_oop_map_count;
duke@0 3395 } else {
jcoomes@938 3396 // Check whether we should add a new map block or whether the last one can
jcoomes@938 3397 // be extended
jcoomes@938 3398 OopMapBlock* const first_map = super->start_of_nonstatic_oop_maps();
jcoomes@938 3399 OopMapBlock* const last_map = first_map + map_count - 1;
jcoomes@938 3400
jcoomes@938 3401 int next_offset = last_map->offset() + last_map->count() * heapOopSize;
duke@0 3402 if (next_offset == first_nonstatic_oop_offset) {
duke@0 3403 // There is no gap bettwen superklass's last oop field and first
duke@0 3404 // local oop field, merge maps.
duke@0 3405 nonstatic_oop_map_count -= 1;
duke@0 3406 } else {
duke@0 3407 // Superklass didn't end with a oop field, add extra maps
jcoomes@938 3408 assert(next_offset < first_nonstatic_oop_offset, "just checking");
duke@0 3409 }
jcoomes@938 3410 map_count += nonstatic_oop_map_count;
duke@0 3411 }
duke@0 3412 }
jcoomes@938 3413 return map_count;
duke@0 3414 }
duke@0 3415
duke@0 3416
duke@0 3417 void ClassFileParser::fill_oop_maps(instanceKlassHandle k,
jcoomes@939 3418 unsigned int nonstatic_oop_map_count,
jcoomes@939 3419 int* nonstatic_oop_offsets,
jcoomes@939 3420 unsigned int* nonstatic_oop_counts) {
duke@0 3421 OopMapBlock* this_oop_map = k->start_of_nonstatic_oop_maps();
jcoomes@938 3422 const instanceKlass* const super = k->superklass();
jcoomes@939 3423 const unsigned int super_count = super ? super->nonstatic_oop_map_count() : 0;
jcoomes@938 3424 if (super_count > 0) {
jcoomes@938 3425 // Copy maps from superklass
duke@0 3426 OopMapBlock* super_oop_map = super->start_of_nonstatic_oop_maps();
jcoomes@939 3427 for (unsigned int i = 0; i < super_count; ++i) {
duke@0 3428 *this_oop_map++ = *super_oop_map++;
duke@0 3429 }
duke@0 3430 }
jcoomes@938 3431
duke@0 3432 if (nonstatic_oop_map_count > 0) {
jcoomes@938 3433 if (super_count + nonstatic_oop_map_count > k->nonstatic_oop_map_count()) {
jcoomes@938 3434 // The counts differ because there is no gap between superklass's last oop
jcoomes@938 3435 // field and the first local oop field. Extend the last oop map copied
duke@0 3436 // from the superklass instead of creating new one.
duke@0 3437 nonstatic_oop_map_count--;
duke@0 3438 nonstatic_oop_offsets++;
duke@0 3439 this_oop_map--;
jcoomes@938 3440 this_oop_map->set_count(this_oop_map->count() + *nonstatic_oop_counts++);
duke@0 3441 this_oop_map++;
duke@0 3442 }
jcoomes@938 3443
duke@0 3444 // Add new map blocks, fill them
duke@0 3445 while (nonstatic_oop_map_count-- > 0) {
duke@0 3446 this_oop_map->set_offset(*nonstatic_oop_offsets++);
jcoomes@938 3447 this_oop_map->set_count(*nonstatic_oop_counts++);
duke@0 3448 this_oop_map++;
duke@0 3449 }
jcoomes@938 3450 assert(k->start_of_nonstatic_oop_maps() + k->nonstatic_oop_map_count() ==
jcoomes@938 3451 this_oop_map, "sanity");
duke@0 3452 }
duke@0 3453 }
duke@0 3454
duke@0 3455
duke@0 3456 void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
duke@0 3457 klassOop super = k->super();
duke@0 3458
duke@0 3459 // Check if this klass has an empty finalize method (i.e. one with return bytecode only),
duke@0 3460 // in which case we don't have to register objects as finalizable
duke@0 3461 if (!_has_empty_finalizer) {
duke@0 3462 if (_has_finalizer ||
duke@0 3463 (super != NULL && super->klass_part()->has_finalizer())) {
duke@0 3464 k->set_has_finalizer();
duke@0 3465 }
duke@0 3466 }
duke@0 3467
duke@0 3468 #ifdef ASSERT
duke@0 3469 bool f = false;
duke@0 3470 methodOop m = k->lookup_method(vmSymbols::finalize_method_name(),
duke@0 3471 vmSymbols::void_method_signature());
duke@0 3472 if (m != NULL && !m->is_empty_method()) {
duke@0 3473 f = true;
duke@0 3474 }
duke@0 3475 assert(f == k->has_finalizer(), "inconsistent has_finalizer");
duke@0 3476 #endif
duke@0 3477
duke@0 3478 // Check if this klass supports the java.lang.Cloneable interface
duke@0 3479 if (SystemDictionary::cloneable_klass_loaded()) {
duke@0 3480 if (k->is_subtype_of(SystemDictionary::cloneable_klass())) {
duke@0 3481 k->set_is_cloneable();
duke@0 3482 }
duke@0 3483 }
duke@0 3484
duke@0 3485 // Check if this klass has a vanilla default constructor
duke@0 3486 if (super == NULL) {
duke@0 3487 // java.lang.Object has empty default constructor
duke@0 3488 k->set_has_vanilla_constructor();
duke@0 3489 } else {
duke@0 3490 if (Klass::cast(super)->has_vanilla_constructor() &&
duke@0 3491 _has_vanilla_constructor) {
duke@0 3492 k->set_has_vanilla_constructor();
duke@0 3493 }
duke@0 3494 #ifdef ASSERT
duke@0 3495 bool v = false;
duke@0 3496 if (Klass::cast(super)->has_vanilla_constructor()) {
duke@0 3497 methodOop constructor = k->find_method(vmSymbols::object_initializer_name(
duke@0 3498 ), vmSymbols::void_method_signature());
duke@0 3499 if (constructor != NULL && constructor->is_vanilla_constructor()) {
duke@0 3500 v = true;
duke@0 3501 }
duke@0 3502 }
duke@0 3503 assert(v == k->has_vanilla_constructor(), "inconsistent has_vanilla_constructor");
duke@0 3504 #endif
duke@0 3505 }
duke@0 3506
duke@0 3507 // If it cannot be fast-path allocated, set a bit in the layout helper.
duke@0 3508 // See documentation of instanceKlass::can_be_fastpath_allocated().
duke@0 3509 assert(k->size_helper() > 0, "layout_helper is initialized");
duke@0 3510 if ((!RegisterFinalizersAtInit && k->has_finalizer())
duke@0 3511 || k->is_abstract() || k->is_interface()
duke@0 3512 || (k->name() == vmSymbols::java_lang_Class()
duke@0 3513 && k->class_loader() == NULL)
duke@0 3514 || k->size_helper() >= FastAllocateSizeLimit) {
duke@0 3515 // Forbid fast-path allocation.
duke@0 3516 jint lh = Klass::instance_layout_helper(k->size_helper(), true);
duke@0 3517 k->set_layout_helper(lh);
duke@0 3518 }
duke@0 3519 }
duke@0 3520
duke@0 3521
duke@0 3522 // utility method for appending and array with check for duplicates
duke@0 3523
duke@0 3524 void append_interfaces(objArrayHan