src/share/vm/classfile/classFileParser.cpp

changeset 435
a61af66fc99e
child 527
ebec5b9731e2
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/classfile/classFileParser.cpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,4014 @@
     1.4 +/*
     1.5 + * Copyright 1997-2007 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "incls/_precompiled.incl"
    1.29 +#include "incls/_classFileParser.cpp.incl"
    1.30 +
    1.31 +// We generally try to create the oops directly when parsing, rather than allocating
    1.32 +// temporary data structures and copying the bytes twice. A temporary area is only
    1.33 +// needed when parsing utf8 entries in the constant pool and when parsing line number
    1.34 +// tables.
    1.35 +
    1.36 +// We add assert in debug mode when class format is not checked.
    1.37 +
    1.38 +#define JAVA_CLASSFILE_MAGIC              0xCAFEBABE
    1.39 +#define JAVA_MIN_SUPPORTED_VERSION        45
    1.40 +#define JAVA_MAX_SUPPORTED_VERSION        50
    1.41 +#define JAVA_MAX_SUPPORTED_MINOR_VERSION  0
    1.42 +
    1.43 +// Used for two backward compatibility reasons:
    1.44 +// - to check for new additions to the class file format in JDK1.5
    1.45 +// - to check for bug fixes in the format checker in JDK1.5
    1.46 +#define JAVA_1_5_VERSION                  49
    1.47 +
    1.48 +// Used for backward compatibility reasons:
    1.49 +// - to check for javac bug fixes that happened after 1.5
    1.50 +#define JAVA_6_VERSION                    50
    1.51 +
    1.52 +
    1.53 +void ClassFileParser::parse_constant_pool_entries(constantPoolHandle cp, int length, TRAPS) {
    1.54 +  // Use a local copy of ClassFileStream. It helps the C++ compiler to optimize
    1.55 +  // this function (_current can be allocated in a register, with scalar
    1.56 +  // replacement of aggregates). The _current pointer is copied back to
    1.57 +  // stream() when this function returns. DON'T call another method within
    1.58 +  // this method that uses stream().
    1.59 +  ClassFileStream* cfs0 = stream();
    1.60 +  ClassFileStream cfs1 = *cfs0;
    1.61 +  ClassFileStream* cfs = &cfs1;
    1.62 +#ifdef ASSERT
    1.63 +  u1* old_current = cfs0->current();
    1.64 +#endif
    1.65 +
    1.66 +  // Used for batching symbol allocations.
    1.67 +  const char* names[SymbolTable::symbol_alloc_batch_size];
    1.68 +  int lengths[SymbolTable::symbol_alloc_batch_size];
    1.69 +  int indices[SymbolTable::symbol_alloc_batch_size];
    1.70 +  unsigned int hashValues[SymbolTable::symbol_alloc_batch_size];
    1.71 +  int names_count = 0;
    1.72 +
    1.73 +  // parsing  Index 0 is unused
    1.74 +  for (int index = 1; index < length; index++) {
    1.75 +    // Each of the following case guarantees one more byte in the stream
    1.76 +    // for the following tag or the access_flags following constant pool,
    1.77 +    // so we don't need bounds-check for reading tag.
    1.78 +    u1 tag = cfs->get_u1_fast();
    1.79 +    switch (tag) {
    1.80 +      case JVM_CONSTANT_Class :
    1.81 +        {
    1.82 +          cfs->guarantee_more(3, CHECK);  // name_index, tag/access_flags
    1.83 +          u2 name_index = cfs->get_u2_fast();
    1.84 +          cp->klass_index_at_put(index, name_index);
    1.85 +        }
    1.86 +        break;
    1.87 +      case JVM_CONSTANT_Fieldref :
    1.88 +        {
    1.89 +          cfs->guarantee_more(5, CHECK);  // class_index, name_and_type_index, tag/access_flags
    1.90 +          u2 class_index = cfs->get_u2_fast();
    1.91 +          u2 name_and_type_index = cfs->get_u2_fast();
    1.92 +          cp->field_at_put(index, class_index, name_and_type_index);
    1.93 +        }
    1.94 +        break;
    1.95 +      case JVM_CONSTANT_Methodref :
    1.96 +        {
    1.97 +          cfs->guarantee_more(5, CHECK);  // class_index, name_and_type_index, tag/access_flags
    1.98 +          u2 class_index = cfs->get_u2_fast();
    1.99 +          u2 name_and_type_index = cfs->get_u2_fast();
   1.100 +          cp->method_at_put(index, class_index, name_and_type_index);
   1.101 +        }
   1.102 +        break;
   1.103 +      case JVM_CONSTANT_InterfaceMethodref :
   1.104 +        {
   1.105 +          cfs->guarantee_more(5, CHECK);  // class_index, name_and_type_index, tag/access_flags
   1.106 +          u2 class_index = cfs->get_u2_fast();
   1.107 +          u2 name_and_type_index = cfs->get_u2_fast();
   1.108 +          cp->interface_method_at_put(index, class_index, name_and_type_index);
   1.109 +        }
   1.110 +        break;
   1.111 +      case JVM_CONSTANT_String :
   1.112 +        {
   1.113 +          cfs->guarantee_more(3, CHECK);  // string_index, tag/access_flags
   1.114 +          u2 string_index = cfs->get_u2_fast();
   1.115 +          cp->string_index_at_put(index, string_index);
   1.116 +        }
   1.117 +        break;
   1.118 +      case JVM_CONSTANT_Integer :
   1.119 +        {
   1.120 +          cfs->guarantee_more(5, CHECK);  // bytes, tag/access_flags
   1.121 +          u4 bytes = cfs->get_u4_fast();
   1.122 +          cp->int_at_put(index, (jint) bytes);
   1.123 +        }
   1.124 +        break;
   1.125 +      case JVM_CONSTANT_Float :
   1.126 +        {
   1.127 +          cfs->guarantee_more(5, CHECK);  // bytes, tag/access_flags
   1.128 +          u4 bytes = cfs->get_u4_fast();
   1.129 +          cp->float_at_put(index, *(jfloat*)&bytes);
   1.130 +        }
   1.131 +        break;
   1.132 +      case JVM_CONSTANT_Long :
   1.133 +        // A mangled type might cause you to overrun allocated memory
   1.134 +        guarantee_property(index+1 < length,
   1.135 +                           "Invalid constant pool entry %u in class file %s",
   1.136 +                           index, CHECK);
   1.137 +        {
   1.138 +          cfs->guarantee_more(9, CHECK);  // bytes, tag/access_flags
   1.139 +          u8 bytes = cfs->get_u8_fast();
   1.140 +          cp->long_at_put(index, bytes);
   1.141 +        }
   1.142 +        index++;   // Skip entry following eigth-byte constant, see JVM book p. 98
   1.143 +        break;
   1.144 +      case JVM_CONSTANT_Double :
   1.145 +        // A mangled type might cause you to overrun allocated memory
   1.146 +        guarantee_property(index+1 < length,
   1.147 +                           "Invalid constant pool entry %u in class file %s",
   1.148 +                           index, CHECK);
   1.149 +        {
   1.150 +          cfs->guarantee_more(9, CHECK);  // bytes, tag/access_flags
   1.151 +          u8 bytes = cfs->get_u8_fast();
   1.152 +          cp->double_at_put(index, *(jdouble*)&bytes);
   1.153 +        }
   1.154 +        index++;   // Skip entry following eigth-byte constant, see JVM book p. 98
   1.155 +        break;
   1.156 +      case JVM_CONSTANT_NameAndType :
   1.157 +        {
   1.158 +          cfs->guarantee_more(5, CHECK);  // name_index, signature_index, tag/access_flags
   1.159 +          u2 name_index = cfs->get_u2_fast();
   1.160 +          u2 signature_index = cfs->get_u2_fast();
   1.161 +          cp->name_and_type_at_put(index, name_index, signature_index);
   1.162 +        }
   1.163 +        break;
   1.164 +      case JVM_CONSTANT_Utf8 :
   1.165 +        {
   1.166 +          cfs->guarantee_more(2, CHECK);  // utf8_length
   1.167 +          u2  utf8_length = cfs->get_u2_fast();
   1.168 +          u1* utf8_buffer = cfs->get_u1_buffer();
   1.169 +          assert(utf8_buffer != NULL, "null utf8 buffer");
   1.170 +          // Got utf8 string, guarantee utf8_length+1 bytes, set stream position forward.
   1.171 +          cfs->guarantee_more(utf8_length+1, CHECK);  // utf8 string, tag/access_flags
   1.172 +          cfs->skip_u1_fast(utf8_length);
   1.173 +          // Before storing the symbol, make sure it's legal
   1.174 +          if (_need_verify) {
   1.175 +            verify_legal_utf8((unsigned char*)utf8_buffer, utf8_length, CHECK);
   1.176 +          }
   1.177 +
   1.178 +          unsigned int hash;
   1.179 +          symbolOop result = SymbolTable::lookup_only((char*)utf8_buffer, utf8_length, hash);
   1.180 +          if (result == NULL) {
   1.181 +            names[names_count] = (char*)utf8_buffer;
   1.182 +            lengths[names_count] = utf8_length;
   1.183 +            indices[names_count] = index;
   1.184 +            hashValues[names_count++] = hash;
   1.185 +            if (names_count == SymbolTable::symbol_alloc_batch_size) {
   1.186 +              oopFactory::new_symbols(cp, names_count, names, lengths, indices, hashValues, CHECK);
   1.187 +              names_count = 0;
   1.188 +            }
   1.189 +          } else {
   1.190 +            cp->symbol_at_put(index, result);
   1.191 +          }
   1.192 +        }
   1.193 +        break;
   1.194 +      default:
   1.195 +        classfile_parse_error(
   1.196 +          "Unknown constant tag %u in class file %s", tag, CHECK);
   1.197 +        break;
   1.198 +    }
   1.199 +  }
   1.200 +
   1.201 +  // Allocate the remaining symbols
   1.202 +  if (names_count > 0) {
   1.203 +    oopFactory::new_symbols(cp, names_count, names, lengths, indices, hashValues, CHECK);
   1.204 +  }
   1.205 +
   1.206 +  // Copy _current pointer of local copy back to stream().
   1.207 +#ifdef ASSERT
   1.208 +  assert(cfs0->current() == old_current, "non-exclusive use of stream()");
   1.209 +#endif
   1.210 +  cfs0->set_current(cfs1.current());
   1.211 +}
   1.212 +
   1.213 +bool inline valid_cp_range(int index, int length) { return (index > 0 && index < length); }
   1.214 +
   1.215 +constantPoolHandle ClassFileParser::parse_constant_pool(TRAPS) {
   1.216 +  ClassFileStream* cfs = stream();
   1.217 +  constantPoolHandle nullHandle;
   1.218 +
   1.219 +  cfs->guarantee_more(3, CHECK_(nullHandle)); // length, first cp tag
   1.220 +  u2 length = cfs->get_u2_fast();
   1.221 +  guarantee_property(
   1.222 +    length >= 1, "Illegal constant pool size %u in class file %s",
   1.223 +    length, CHECK_(nullHandle));
   1.224 +  constantPoolOop constant_pool =
   1.225 +                      oopFactory::new_constantPool(length, CHECK_(nullHandle));
   1.226 +  constantPoolHandle cp (THREAD, constant_pool);
   1.227 +
   1.228 +  cp->set_partially_loaded();    // Enables heap verify to work on partial constantPoolOops
   1.229 +
   1.230 +  // parsing constant pool entries
   1.231 +  parse_constant_pool_entries(cp, length, CHECK_(nullHandle));
   1.232 +
   1.233 +  int index = 1;  // declared outside of loops for portability
   1.234 +
   1.235 +  // first verification pass - validate cross references and fixup class and string constants
   1.236 +  for (index = 1; index < length; index++) {          // Index 0 is unused
   1.237 +    switch (cp->tag_at(index).value()) {
   1.238 +      case JVM_CONSTANT_Class :
   1.239 +        ShouldNotReachHere();     // Only JVM_CONSTANT_ClassIndex should be present
   1.240 +        break;
   1.241 +      case JVM_CONSTANT_Fieldref :
   1.242 +        // fall through
   1.243 +      case JVM_CONSTANT_Methodref :
   1.244 +        // fall through
   1.245 +      case JVM_CONSTANT_InterfaceMethodref : {
   1.246 +        if (!_need_verify) break;
   1.247 +        int klass_ref_index = cp->klass_ref_index_at(index);
   1.248 +        int name_and_type_ref_index = cp->name_and_type_ref_index_at(index);
   1.249 +        check_property(valid_cp_range(klass_ref_index, length) &&
   1.250 +                       cp->tag_at(klass_ref_index).is_klass_reference(),
   1.251 +                       "Invalid constant pool index %u in class file %s",
   1.252 +                       klass_ref_index,
   1.253 +                       CHECK_(nullHandle));
   1.254 +        check_property(valid_cp_range(name_and_type_ref_index, length) &&
   1.255 +                       cp->tag_at(name_and_type_ref_index).is_name_and_type(),
   1.256 +                       "Invalid constant pool index %u in class file %s",
   1.257 +                       name_and_type_ref_index,
   1.258 +                       CHECK_(nullHandle));
   1.259 +        break;
   1.260 +      }
   1.261 +      case JVM_CONSTANT_String :
   1.262 +        ShouldNotReachHere();     // Only JVM_CONSTANT_StringIndex should be present
   1.263 +        break;
   1.264 +      case JVM_CONSTANT_Integer :
   1.265 +        break;
   1.266 +      case JVM_CONSTANT_Float :
   1.267 +        break;
   1.268 +      case JVM_CONSTANT_Long :
   1.269 +      case JVM_CONSTANT_Double :
   1.270 +        index++;
   1.271 +        check_property(
   1.272 +          (index < length && cp->tag_at(index).is_invalid()),
   1.273 +          "Improper constant pool long/double index %u in class file %s",
   1.274 +          index, CHECK_(nullHandle));
   1.275 +        break;
   1.276 +      case JVM_CONSTANT_NameAndType : {
   1.277 +        if (!_need_verify) break;
   1.278 +        int name_ref_index = cp->name_ref_index_at(index);
   1.279 +        int signature_ref_index = cp->signature_ref_index_at(index);
   1.280 +        check_property(
   1.281 +          valid_cp_range(name_ref_index, length) &&
   1.282 +            cp->tag_at(name_ref_index).is_utf8(),
   1.283 +          "Invalid constant pool index %u in class file %s",
   1.284 +          name_ref_index, CHECK_(nullHandle));
   1.285 +        check_property(
   1.286 +          valid_cp_range(signature_ref_index, length) &&
   1.287 +            cp->tag_at(signature_ref_index).is_utf8(),
   1.288 +          "Invalid constant pool index %u in class file %s",
   1.289 +          signature_ref_index, CHECK_(nullHandle));
   1.290 +        break;
   1.291 +      }
   1.292 +      case JVM_CONSTANT_Utf8 :
   1.293 +        break;
   1.294 +      case JVM_CONSTANT_UnresolvedClass :         // fall-through
   1.295 +      case JVM_CONSTANT_UnresolvedClassInError:
   1.296 +        ShouldNotReachHere();     // Only JVM_CONSTANT_ClassIndex should be present
   1.297 +        break;
   1.298 +      case JVM_CONSTANT_ClassIndex :
   1.299 +        {
   1.300 +          int class_index = cp->klass_index_at(index);
   1.301 +          check_property(
   1.302 +            valid_cp_range(class_index, length) &&
   1.303 +              cp->tag_at(class_index).is_utf8(),
   1.304 +            "Invalid constant pool index %u in class file %s",
   1.305 +            class_index, CHECK_(nullHandle));
   1.306 +          cp->unresolved_klass_at_put(index, cp->symbol_at(class_index));
   1.307 +        }
   1.308 +        break;
   1.309 +      case JVM_CONSTANT_UnresolvedString :
   1.310 +        ShouldNotReachHere();     // Only JVM_CONSTANT_StringIndex should be present
   1.311 +        break;
   1.312 +      case JVM_CONSTANT_StringIndex :
   1.313 +        {
   1.314 +          int string_index = cp->string_index_at(index);
   1.315 +          check_property(
   1.316 +            valid_cp_range(string_index, length) &&
   1.317 +              cp->tag_at(string_index).is_utf8(),
   1.318 +            "Invalid constant pool index %u in class file %s",
   1.319 +            string_index, CHECK_(nullHandle));
   1.320 +          symbolOop sym = cp->symbol_at(string_index);
   1.321 +          cp->unresolved_string_at_put(index, sym);
   1.322 +        }
   1.323 +        break;
   1.324 +      default:
   1.325 +        fatal1("bad constant pool tag value %u", cp->tag_at(index).value());
   1.326 +        ShouldNotReachHere();
   1.327 +        break;
   1.328 +    } // end of switch
   1.329 +  } // end of for
   1.330 +
   1.331 +  if (!_need_verify) {
   1.332 +    return cp;
   1.333 +  }
   1.334 +
   1.335 +  // second verification pass - checks the strings are of the right format.
   1.336 +  for (index = 1; index < length; index++) {
   1.337 +    jbyte tag = cp->tag_at(index).value();
   1.338 +    switch (tag) {
   1.339 +      case JVM_CONSTANT_UnresolvedClass: {
   1.340 +        symbolHandle class_name(THREAD, cp->unresolved_klass_at(index));
   1.341 +        verify_legal_class_name(class_name, CHECK_(nullHandle));
   1.342 +        break;
   1.343 +      }
   1.344 +      case JVM_CONSTANT_Fieldref:
   1.345 +      case JVM_CONSTANT_Methodref:
   1.346 +      case JVM_CONSTANT_InterfaceMethodref: {
   1.347 +        int name_and_type_ref_index = cp->name_and_type_ref_index_at(index);
   1.348 +        // already verified to be utf8
   1.349 +        int name_ref_index = cp->name_ref_index_at(name_and_type_ref_index);
   1.350 +        // already verified to be utf8
   1.351 +        int signature_ref_index = cp->signature_ref_index_at(name_and_type_ref_index);
   1.352 +        symbolHandle name(THREAD, cp->symbol_at(name_ref_index));
   1.353 +        symbolHandle signature(THREAD, cp->symbol_at(signature_ref_index));
   1.354 +        if (tag == JVM_CONSTANT_Fieldref) {
   1.355 +          verify_legal_field_name(name, CHECK_(nullHandle));
   1.356 +          verify_legal_field_signature(name, signature, CHECK_(nullHandle));
   1.357 +        } else {
   1.358 +          verify_legal_method_name(name, CHECK_(nullHandle));
   1.359 +          verify_legal_method_signature(name, signature, CHECK_(nullHandle));
   1.360 +          if (tag == JVM_CONSTANT_Methodref) {
   1.361 +            // 4509014: If a class method name begins with '<', it must be "<init>".
   1.362 +            assert(!name.is_null(), "method name in constant pool is null");
   1.363 +            unsigned int name_len = name->utf8_length();
   1.364 +            assert(name_len > 0, "bad method name");  // already verified as legal name
   1.365 +            if (name->byte_at(0) == '<') {
   1.366 +              if (name() != vmSymbols::object_initializer_name()) {
   1.367 +                classfile_parse_error(
   1.368 +                  "Bad method name at constant pool index %u in class file %s",
   1.369 +                  name_ref_index, CHECK_(nullHandle));
   1.370 +              }
   1.371 +            }
   1.372 +          }
   1.373 +        }
   1.374 +        break;
   1.375 +      }
   1.376 +    }  // end of switch
   1.377 +  }  // end of for
   1.378 +
   1.379 +  return cp;
   1.380 +}
   1.381 +
   1.382 +
   1.383 +class NameSigHash: public ResourceObj {
   1.384 + public:
   1.385 +  symbolOop     _name;       // name
   1.386 +  symbolOop     _sig;        // signature
   1.387 +  NameSigHash*  _next;       // Next entry in hash table
   1.388 +};
   1.389 +
   1.390 +
   1.391 +#define HASH_ROW_SIZE 256
   1.392 +
   1.393 +unsigned int hash(symbolOop name, symbolOop sig) {
   1.394 +  unsigned int raw_hash = 0;
   1.395 +  raw_hash += ((unsigned int)(uintptr_t)name) >> (LogHeapWordSize + 2);
   1.396 +  raw_hash += ((unsigned int)(uintptr_t)sig) >> LogHeapWordSize;
   1.397 +
   1.398 +  return (raw_hash + (unsigned int)(uintptr_t)name) % HASH_ROW_SIZE;
   1.399 +}
   1.400 +
   1.401 +
   1.402 +void initialize_hashtable(NameSigHash** table) {
   1.403 +  memset((void*)table, 0, sizeof(NameSigHash*) * HASH_ROW_SIZE);
   1.404 +}
   1.405 +
   1.406 +// Return false if the name/sig combination is found in table.
   1.407 +// Return true if no duplicate is found. And name/sig is added as a new entry in table.
   1.408 +// The old format checker uses heap sort to find duplicates.
   1.409 +// NOTE: caller should guarantee that GC doesn't happen during the life cycle
   1.410 +// of table since we don't expect symbolOop's to move.
   1.411 +bool put_after_lookup(symbolOop name, symbolOop sig, NameSigHash** table) {
   1.412 +  assert(name != NULL, "name in constant pool is NULL");
   1.413 +
   1.414 +  // First lookup for duplicates
   1.415 +  int index = hash(name, sig);
   1.416 +  NameSigHash* entry = table[index];
   1.417 +  while (entry != NULL) {
   1.418 +    if (entry->_name == name && entry->_sig == sig) {
   1.419 +      return false;
   1.420 +    }
   1.421 +    entry = entry->_next;
   1.422 +  }
   1.423 +
   1.424 +  // No duplicate is found, allocate a new entry and fill it.
   1.425 +  entry = new NameSigHash();
   1.426 +  entry->_name = name;
   1.427 +  entry->_sig = sig;
   1.428 +
   1.429 +  // Insert into hash table
   1.430 +  entry->_next = table[index];
   1.431 +  table[index] = entry;
   1.432 +
   1.433 +  return true;
   1.434 +}
   1.435 +
   1.436 +
   1.437 +objArrayHandle ClassFileParser::parse_interfaces(constantPoolHandle cp,
   1.438 +                                                 int length,
   1.439 +                                                 Handle class_loader,
   1.440 +                                                 Handle protection_domain,
   1.441 +                                                 PerfTraceTime* vmtimer,
   1.442 +                                                 symbolHandle class_name,
   1.443 +                                                 TRAPS) {
   1.444 +  ClassFileStream* cfs = stream();
   1.445 +  assert(length > 0, "only called for length>0");
   1.446 +  objArrayHandle nullHandle;
   1.447 +  objArrayOop interface_oop = oopFactory::new_system_objArray(length, CHECK_(nullHandle));
   1.448 +  objArrayHandle interfaces (THREAD, interface_oop);
   1.449 +
   1.450 +  int index;
   1.451 +  for (index = 0; index < length; index++) {
   1.452 +    u2 interface_index = cfs->get_u2(CHECK_(nullHandle));
   1.453 +    check_property(
   1.454 +      valid_cp_range(interface_index, cp->length()) &&
   1.455 +        cp->tag_at(interface_index).is_unresolved_klass(),
   1.456 +      "Interface name has bad constant pool index %u in class file %s",
   1.457 +      interface_index, CHECK_(nullHandle));
   1.458 +    symbolHandle unresolved_klass (THREAD, cp->klass_name_at(interface_index));
   1.459 +
   1.460 +    // Don't need to check legal name because it's checked when parsing constant pool.
   1.461 +    // But need to make sure it's not an array type.
   1.462 +    guarantee_property(unresolved_klass->byte_at(0) != JVM_SIGNATURE_ARRAY,
   1.463 +                       "Bad interface name in class file %s", CHECK_(nullHandle));
   1.464 +
   1.465 +    vmtimer->suspend();  // do not count recursive loading twice
   1.466 +    // Call resolve_super so classcircularity is checked
   1.467 +    klassOop k = SystemDictionary::resolve_super_or_fail(class_name,
   1.468 +                  unresolved_klass, class_loader, protection_domain,
   1.469 +                  false, CHECK_(nullHandle));
   1.470 +    KlassHandle interf (THREAD, k);
   1.471 +    vmtimer->resume();
   1.472 +
   1.473 +    if (!Klass::cast(interf())->is_interface()) {
   1.474 +      THROW_MSG_(vmSymbols::java_lang_IncompatibleClassChangeError(), "Implementing class", nullHandle);
   1.475 +    }
   1.476 +    interfaces->obj_at_put(index, interf());
   1.477 +  }
   1.478 +
   1.479 +  if (!_need_verify || length <= 1) {
   1.480 +    return interfaces;
   1.481 +  }
   1.482 +
   1.483 +  // Check if there's any duplicates in interfaces
   1.484 +  ResourceMark rm(THREAD);
   1.485 +  NameSigHash** interface_names = NEW_RESOURCE_ARRAY_IN_THREAD(
   1.486 +    THREAD, NameSigHash*, HASH_ROW_SIZE);
   1.487 +  initialize_hashtable(interface_names);
   1.488 +  bool dup = false;
   1.489 +  {
   1.490 +    debug_only(No_Safepoint_Verifier nsv;)
   1.491 +    for (index = 0; index < length; index++) {
   1.492 +      klassOop k = (klassOop)interfaces->obj_at(index);
   1.493 +      symbolOop name = instanceKlass::cast(k)->name();
   1.494 +      // If no duplicates, add (name, NULL) in hashtable interface_names.
   1.495 +      if (!put_after_lookup(name, NULL, interface_names)) {
   1.496 +        dup = true;
   1.497 +        break;
   1.498 +      }
   1.499 +    }
   1.500 +  }
   1.501 +  if (dup) {
   1.502 +    classfile_parse_error("Duplicate interface name in class file %s",
   1.503 +                          CHECK_(nullHandle));
   1.504 +  }
   1.505 +
   1.506 +  return interfaces;
   1.507 +}
   1.508 +
   1.509 +
   1.510 +void ClassFileParser::verify_constantvalue(int constantvalue_index, int signature_index, constantPoolHandle cp, TRAPS) {
   1.511 +  // Make sure the constant pool entry is of a type appropriate to this field
   1.512 +  guarantee_property(
   1.513 +    (constantvalue_index > 0 &&
   1.514 +      constantvalue_index < cp->length()),
   1.515 +    "Bad initial value index %u in ConstantValue attribute in class file %s",
   1.516 +    constantvalue_index, CHECK);
   1.517 +  constantTag value_type = cp->tag_at(constantvalue_index);
   1.518 +  switch ( cp->basic_type_for_signature_at(signature_index) ) {
   1.519 +    case T_LONG:
   1.520 +      guarantee_property(value_type.is_long(), "Inconsistent constant value type in class file %s", CHECK);
   1.521 +      break;
   1.522 +    case T_FLOAT:
   1.523 +      guarantee_property(value_type.is_float(), "Inconsistent constant value type in class file %s", CHECK);
   1.524 +      break;
   1.525 +    case T_DOUBLE:
   1.526 +      guarantee_property(value_type.is_double(), "Inconsistent constant value type in class file %s", CHECK);
   1.527 +      break;
   1.528 +    case T_BYTE: case T_CHAR: case T_SHORT: case T_BOOLEAN: case T_INT:
   1.529 +      guarantee_property(value_type.is_int(), "Inconsistent constant value type in class file %s", CHECK);
   1.530 +      break;
   1.531 +    case T_OBJECT:
   1.532 +      guarantee_property((cp->symbol_at(signature_index)->equals("Ljava/lang/String;", 18)
   1.533 +                         && (value_type.is_string() || value_type.is_unresolved_string())),
   1.534 +                         "Bad string initial value in class file %s", CHECK);
   1.535 +      break;
   1.536 +    default:
   1.537 +      classfile_parse_error(
   1.538 +        "Unable to set initial value %u in class file %s",
   1.539 +        constantvalue_index, CHECK);
   1.540 +  }
   1.541 +}
   1.542 +
   1.543 +
   1.544 +// Parse attributes for a field.
   1.545 +void ClassFileParser::parse_field_attributes(constantPoolHandle cp,
   1.546 +                                             u2 attributes_count,
   1.547 +                                             bool is_static, u2 signature_index,
   1.548 +                                             u2* constantvalue_index_addr,
   1.549 +                                             bool* is_synthetic_addr,
   1.550 +                                             u2* generic_signature_index_addr,
   1.551 +                                             typeArrayHandle* field_annotations,
   1.552 +                                             TRAPS) {
   1.553 +  ClassFileStream* cfs = stream();
   1.554 +  assert(attributes_count > 0, "length should be greater than 0");
   1.555 +  u2 constantvalue_index = 0;
   1.556 +  u2 generic_signature_index = 0;
   1.557 +  bool is_synthetic = false;
   1.558 +  u1* runtime_visible_annotations = NULL;
   1.559 +  int runtime_visible_annotations_length = 0;
   1.560 +  u1* runtime_invisible_annotations = NULL;
   1.561 +  int runtime_invisible_annotations_length = 0;
   1.562 +  while (attributes_count--) {
   1.563 +    cfs->guarantee_more(6, CHECK);  // attribute_name_index, attribute_length
   1.564 +    u2 attribute_name_index = cfs->get_u2_fast();
   1.565 +    u4 attribute_length = cfs->get_u4_fast();
   1.566 +    check_property(valid_cp_range(attribute_name_index, cp->length()) &&
   1.567 +                   cp->tag_at(attribute_name_index).is_utf8(),
   1.568 +                   "Invalid field attribute index %u in class file %s",
   1.569 +                   attribute_name_index,
   1.570 +                   CHECK);
   1.571 +    symbolOop attribute_name = cp->symbol_at(attribute_name_index);
   1.572 +    if (is_static && attribute_name == vmSymbols::tag_constant_value()) {
   1.573 +      // ignore if non-static
   1.574 +      if (constantvalue_index != 0) {
   1.575 +        classfile_parse_error("Duplicate ConstantValue attribute in class file %s", CHECK);
   1.576 +      }
   1.577 +      check_property(
   1.578 +        attribute_length == 2,
   1.579 +        "Invalid ConstantValue field attribute length %u in class file %s",
   1.580 +        attribute_length, CHECK);
   1.581 +      constantvalue_index = cfs->get_u2(CHECK);
   1.582 +      if (_need_verify) {
   1.583 +        verify_constantvalue(constantvalue_index, signature_index, cp, CHECK);
   1.584 +      }
   1.585 +    } else if (attribute_name == vmSymbols::tag_synthetic()) {
   1.586 +      if (attribute_length != 0) {
   1.587 +        classfile_parse_error(
   1.588 +          "Invalid Synthetic field attribute length %u in class file %s",
   1.589 +          attribute_length, CHECK);
   1.590 +      }
   1.591 +      is_synthetic = true;
   1.592 +    } else if (attribute_name == vmSymbols::tag_deprecated()) { // 4276120
   1.593 +      if (attribute_length != 0) {
   1.594 +        classfile_parse_error(
   1.595 +          "Invalid Deprecated field attribute length %u in class file %s",
   1.596 +          attribute_length, CHECK);
   1.597 +      }
   1.598 +    } else if (_major_version >= JAVA_1_5_VERSION) {
   1.599 +      if (attribute_name == vmSymbols::tag_signature()) {
   1.600 +        if (attribute_length != 2) {
   1.601 +          classfile_parse_error(
   1.602 +            "Wrong size %u for field's Signature attribute in class file %s",
   1.603 +            attribute_length, CHECK);
   1.604 +        }
   1.605 +        generic_signature_index = cfs->get_u2(CHECK);
   1.606 +      } else if (attribute_name == vmSymbols::tag_runtime_visible_annotations()) {
   1.607 +        runtime_visible_annotations_length = attribute_length;
   1.608 +        runtime_visible_annotations = cfs->get_u1_buffer();
   1.609 +        assert(runtime_visible_annotations != NULL, "null visible annotations");
   1.610 +        cfs->skip_u1(runtime_visible_annotations_length, CHECK);
   1.611 +      } else if (PreserveAllAnnotations && attribute_name == vmSymbols::tag_runtime_invisible_annotations()) {
   1.612 +        runtime_invisible_annotations_length = attribute_length;
   1.613 +        runtime_invisible_annotations = cfs->get_u1_buffer();
   1.614 +        assert(runtime_invisible_annotations != NULL, "null invisible annotations");
   1.615 +        cfs->skip_u1(runtime_invisible_annotations_length, CHECK);
   1.616 +      } else {
   1.617 +        cfs->skip_u1(attribute_length, CHECK);  // Skip unknown attributes
   1.618 +      }
   1.619 +    } else {
   1.620 +      cfs->skip_u1(attribute_length, CHECK);  // Skip unknown attributes
   1.621 +    }
   1.622 +  }
   1.623 +
   1.624 +  *constantvalue_index_addr = constantvalue_index;
   1.625 +  *is_synthetic_addr = is_synthetic;
   1.626 +  *generic_signature_index_addr = generic_signature_index;
   1.627 +  *field_annotations = assemble_annotations(runtime_visible_annotations,
   1.628 +                                            runtime_visible_annotations_length,
   1.629 +                                            runtime_invisible_annotations,
   1.630 +                                            runtime_invisible_annotations_length,
   1.631 +                                            CHECK);
   1.632 +  return;
   1.633 +}
   1.634 +
   1.635 +
   1.636 +// Field allocation types. Used for computing field offsets.
   1.637 +
   1.638 +enum FieldAllocationType {
   1.639 +  STATIC_OOP,           // Oops
   1.640 +  STATIC_BYTE,          // Boolean, Byte, char
   1.641 +  STATIC_SHORT,         // shorts
   1.642 +  STATIC_WORD,          // ints
   1.643 +  STATIC_DOUBLE,        // long or double
   1.644 +  STATIC_ALIGNED_DOUBLE,// aligned long or double
   1.645 +  NONSTATIC_OOP,
   1.646 +  NONSTATIC_BYTE,
   1.647 +  NONSTATIC_SHORT,
   1.648 +  NONSTATIC_WORD,
   1.649 +  NONSTATIC_DOUBLE,
   1.650 +  NONSTATIC_ALIGNED_DOUBLE
   1.651 +};
   1.652 +
   1.653 +
   1.654 +struct FieldAllocationCount {
   1.655 +  int static_oop_count;
   1.656 +  int static_byte_count;
   1.657 +  int static_short_count;
   1.658 +  int static_word_count;
   1.659 +  int static_double_count;
   1.660 +  int nonstatic_oop_count;
   1.661 +  int nonstatic_byte_count;
   1.662 +  int nonstatic_short_count;
   1.663 +  int nonstatic_word_count;
   1.664 +  int nonstatic_double_count;
   1.665 +};
   1.666 +
   1.667 +typeArrayHandle ClassFileParser::parse_fields(constantPoolHandle cp, bool is_interface,
   1.668 +                                              struct FieldAllocationCount *fac,
   1.669 +                                              objArrayHandle* fields_annotations, TRAPS) {
   1.670 +  ClassFileStream* cfs = stream();
   1.671 +  typeArrayHandle nullHandle;
   1.672 +  cfs->guarantee_more(2, CHECK_(nullHandle));  // length
   1.673 +  u2 length = cfs->get_u2_fast();
   1.674 +  // Tuples of shorts [access, name index, sig index, initial value index, byte offset, generic signature index]
   1.675 +  typeArrayOop new_fields = oopFactory::new_permanent_shortArray(length*instanceKlass::next_offset, CHECK_(nullHandle));
   1.676 +  typeArrayHandle fields(THREAD, new_fields);
   1.677 +
   1.678 +  int index = 0;
   1.679 +  typeArrayHandle field_annotations;
   1.680 +  for (int n = 0; n < length; n++) {
   1.681 +    cfs->guarantee_more(8, CHECK_(nullHandle));  // access_flags, name_index, descriptor_index, attributes_count
   1.682 +
   1.683 +    AccessFlags access_flags;
   1.684 +    jint flags = cfs->get_u2_fast() & JVM_RECOGNIZED_FIELD_MODIFIERS;
   1.685 +    verify_legal_field_modifiers(flags, is_interface, CHECK_(nullHandle));
   1.686 +    access_flags.set_flags(flags);
   1.687 +
   1.688 +    u2 name_index = cfs->get_u2_fast();
   1.689 +    int cp_size = cp->length();
   1.690 +    check_property(
   1.691 +      valid_cp_range(name_index, cp_size) && cp->tag_at(name_index).is_utf8(),
   1.692 +      "Invalid constant pool index %u for field name in class file %s",
   1.693 +      name_index, CHECK_(nullHandle));
   1.694 +    symbolHandle name(THREAD, cp->symbol_at(name_index));
   1.695 +    verify_legal_field_name(name, CHECK_(nullHandle));
   1.696 +
   1.697 +    u2 signature_index = cfs->get_u2_fast();
   1.698 +    check_property(
   1.699 +      valid_cp_range(signature_index, cp_size) &&
   1.700 +        cp->tag_at(signature_index).is_utf8(),
   1.701 +      "Invalid constant pool index %u for field signature in class file %s",
   1.702 +      signature_index, CHECK_(nullHandle));
   1.703 +    symbolHandle sig(THREAD, cp->symbol_at(signature_index));
   1.704 +    verify_legal_field_signature(name, sig, CHECK_(nullHandle));
   1.705 +
   1.706 +    u2 constantvalue_index = 0;
   1.707 +    bool is_synthetic = false;
   1.708 +    u2 generic_signature_index = 0;
   1.709 +    bool is_static = access_flags.is_static();
   1.710 +
   1.711 +    u2 attributes_count = cfs->get_u2_fast();
   1.712 +    if (attributes_count > 0) {
   1.713 +      parse_field_attributes(cp, attributes_count, is_static, signature_index,
   1.714 +                             &constantvalue_index, &is_synthetic,
   1.715 +                             &generic_signature_index, &field_annotations,
   1.716 +                             CHECK_(nullHandle));
   1.717 +      if (field_annotations.not_null()) {
   1.718 +        if (fields_annotations->is_null()) {
   1.719 +          objArrayOop md = oopFactory::new_system_objArray(length, CHECK_(nullHandle));
   1.720 +          *fields_annotations = objArrayHandle(THREAD, md);
   1.721 +        }
   1.722 +        (*fields_annotations)->obj_at_put(n, field_annotations());
   1.723 +      }
   1.724 +      if (is_synthetic) {
   1.725 +        access_flags.set_is_synthetic();
   1.726 +      }
   1.727 +    }
   1.728 +
   1.729 +    fields->short_at_put(index++, access_flags.as_short());
   1.730 +    fields->short_at_put(index++, name_index);
   1.731 +    fields->short_at_put(index++, signature_index);
   1.732 +    fields->short_at_put(index++, constantvalue_index);
   1.733 +
   1.734 +    // Remember how many oops we encountered and compute allocation type
   1.735 +    BasicType type = cp->basic_type_for_signature_at(signature_index);
   1.736 +    FieldAllocationType atype;
   1.737 +    if ( is_static ) {
   1.738 +      switch ( type ) {
   1.739 +        case  T_BOOLEAN:
   1.740 +        case  T_BYTE:
   1.741 +          fac->static_byte_count++;
   1.742 +          atype = STATIC_BYTE;
   1.743 +          break;
   1.744 +        case  T_LONG:
   1.745 +        case  T_DOUBLE:
   1.746 +          if (Universe::field_type_should_be_aligned(type)) {
   1.747 +            atype = STATIC_ALIGNED_DOUBLE;
   1.748 +          } else {
   1.749 +            atype = STATIC_DOUBLE;
   1.750 +          }
   1.751 +          fac->static_double_count++;
   1.752 +          break;
   1.753 +        case  T_CHAR:
   1.754 +        case  T_SHORT:
   1.755 +          fac->static_short_count++;
   1.756 +          atype = STATIC_SHORT;
   1.757 +          break;
   1.758 +        case  T_FLOAT:
   1.759 +        case  T_INT:
   1.760 +          fac->static_word_count++;
   1.761 +          atype = STATIC_WORD;
   1.762 +          break;
   1.763 +        case  T_ARRAY:
   1.764 +        case  T_OBJECT:
   1.765 +          fac->static_oop_count++;
   1.766 +          atype = STATIC_OOP;
   1.767 +          break;
   1.768 +        case  T_ADDRESS:
   1.769 +        case  T_VOID:
   1.770 +        default:
   1.771 +          assert(0, "bad field type");
   1.772 +      }
   1.773 +    } else {
   1.774 +      switch ( type ) {
   1.775 +        case  T_BOOLEAN:
   1.776 +        case  T_BYTE:
   1.777 +          fac->nonstatic_byte_count++;
   1.778 +          atype = NONSTATIC_BYTE;
   1.779 +          break;
   1.780 +        case  T_LONG:
   1.781 +        case  T_DOUBLE:
   1.782 +          if (Universe::field_type_should_be_aligned(type)) {
   1.783 +            atype = NONSTATIC_ALIGNED_DOUBLE;
   1.784 +          } else {
   1.785 +            atype = NONSTATIC_DOUBLE;
   1.786 +          }
   1.787 +          fac->nonstatic_double_count++;
   1.788 +          break;
   1.789 +        case  T_CHAR:
   1.790 +        case  T_SHORT:
   1.791 +          fac->nonstatic_short_count++;
   1.792 +          atype = NONSTATIC_SHORT;
   1.793 +          break;
   1.794 +        case  T_FLOAT:
   1.795 +        case  T_INT:
   1.796 +          fac->nonstatic_word_count++;
   1.797 +          atype = NONSTATIC_WORD;
   1.798 +          break;
   1.799 +        case  T_ARRAY:
   1.800 +        case  T_OBJECT:
   1.801 +          fac->nonstatic_oop_count++;
   1.802 +          atype = NONSTATIC_OOP;
   1.803 +          break;
   1.804 +        case  T_ADDRESS:
   1.805 +        case  T_VOID:
   1.806 +        default:
   1.807 +          assert(0, "bad field type");
   1.808 +      }
   1.809 +    }
   1.810 +
   1.811 +    // The correct offset is computed later (all oop fields will be located together)
   1.812 +    // We temporarily store the allocation type in the offset field
   1.813 +    fields->short_at_put(index++, atype);
   1.814 +    fields->short_at_put(index++, 0);  // Clear out high word of byte offset
   1.815 +    fields->short_at_put(index++, generic_signature_index);
   1.816 +  }
   1.817 +
   1.818 +  if (_need_verify && length > 1) {
   1.819 +    // Check duplicated fields
   1.820 +    ResourceMark rm(THREAD);
   1.821 +    NameSigHash** names_and_sigs = NEW_RESOURCE_ARRAY_IN_THREAD(
   1.822 +      THREAD, NameSigHash*, HASH_ROW_SIZE);
   1.823 +    initialize_hashtable(names_and_sigs);
   1.824 +    bool dup = false;
   1.825 +    {
   1.826 +      debug_only(No_Safepoint_Verifier nsv;)
   1.827 +      for (int i = 0; i < length*instanceKlass::next_offset; i += instanceKlass::next_offset) {
   1.828 +        int name_index = fields->ushort_at(i + instanceKlass::name_index_offset);
   1.829 +        symbolOop name = cp->symbol_at(name_index);
   1.830 +        int sig_index = fields->ushort_at(i + instanceKlass::signature_index_offset);
   1.831 +        symbolOop sig = cp->symbol_at(sig_index);
   1.832 +        // If no duplicates, add name/signature in hashtable names_and_sigs.
   1.833 +        if (!put_after_lookup(name, sig, names_and_sigs)) {
   1.834 +          dup = true;
   1.835 +          break;
   1.836 +        }
   1.837 +      }
   1.838 +    }
   1.839 +    if (dup) {
   1.840 +      classfile_parse_error("Duplicate field name&signature in class file %s",
   1.841 +                            CHECK_(nullHandle));
   1.842 +    }
   1.843 +  }
   1.844 +
   1.845 +  return fields;
   1.846 +}
   1.847 +
   1.848 +
   1.849 +static void copy_u2_with_conversion(u2* dest, u2* src, int length) {
   1.850 +  while (length-- > 0) {
   1.851 +    *dest++ = Bytes::get_Java_u2((u1*) (src++));
   1.852 +  }
   1.853 +}
   1.854 +
   1.855 +
   1.856 +typeArrayHandle ClassFileParser::parse_exception_table(u4 code_length,
   1.857 +                                                       u4 exception_table_length,
   1.858 +                                                       constantPoolHandle cp,
   1.859 +                                                       TRAPS) {
   1.860 +  ClassFileStream* cfs = stream();
   1.861 +  typeArrayHandle nullHandle;
   1.862 +
   1.863 +  // 4-tuples of ints [start_pc, end_pc, handler_pc, catch_type index]
   1.864 +  typeArrayOop eh = oopFactory::new_permanent_intArray(exception_table_length*4, CHECK_(nullHandle));
   1.865 +  typeArrayHandle exception_handlers = typeArrayHandle(THREAD, eh);
   1.866 +
   1.867 +  int index = 0;
   1.868 +  cfs->guarantee_more(8 * exception_table_length, CHECK_(nullHandle)); // start_pc, end_pc, handler_pc, catch_type_index
   1.869 +  for (unsigned int i = 0; i < exception_table_length; i++) {
   1.870 +    u2 start_pc = cfs->get_u2_fast();
   1.871 +    u2 end_pc = cfs->get_u2_fast();
   1.872 +    u2 handler_pc = cfs->get_u2_fast();
   1.873 +    u2 catch_type_index = cfs->get_u2_fast();
   1.874 +    // Will check legal target after parsing code array in verifier.
   1.875 +    if (_need_verify) {
   1.876 +      guarantee_property((start_pc < end_pc) && (end_pc <= code_length),
   1.877 +                         "Illegal exception table range in class file %s", CHECK_(nullHandle));
   1.878 +      guarantee_property(handler_pc < code_length,
   1.879 +                         "Illegal exception table handler in class file %s", CHECK_(nullHandle));
   1.880 +      if (catch_type_index != 0) {
   1.881 +        guarantee_property(valid_cp_range(catch_type_index, cp->length()) &&
   1.882 +                          (cp->tag_at(catch_type_index).is_klass() ||
   1.883 +                           cp->tag_at(catch_type_index).is_unresolved_klass()),
   1.884 +                           "Catch type in exception table has bad constant type in class file %s", CHECK_(nullHandle));
   1.885 +      }
   1.886 +    }
   1.887 +    exception_handlers->int_at_put(index++, start_pc);
   1.888 +    exception_handlers->int_at_put(index++, end_pc);
   1.889 +    exception_handlers->int_at_put(index++, handler_pc);
   1.890 +    exception_handlers->int_at_put(index++, catch_type_index);
   1.891 +  }
   1.892 +  return exception_handlers;
   1.893 +}
   1.894 +
   1.895 +void ClassFileParser::parse_linenumber_table(
   1.896 +    u4 code_attribute_length, u4 code_length,
   1.897 +    CompressedLineNumberWriteStream** write_stream, TRAPS) {
   1.898 +  ClassFileStream* cfs = stream();
   1.899 +  unsigned int num_entries = cfs->get_u2(CHECK);
   1.900 +
   1.901 +  // Each entry is a u2 start_pc, and a u2 line_number
   1.902 +  unsigned int length_in_bytes = num_entries * (sizeof(u2) + sizeof(u2));
   1.903 +
   1.904 +  // Verify line number attribute and table length
   1.905 +  check_property(
   1.906 +    code_attribute_length == sizeof(u2) + length_in_bytes,
   1.907 +    "LineNumberTable attribute has wrong length in class file %s", CHECK);
   1.908 +
   1.909 +  cfs->guarantee_more(length_in_bytes, CHECK);
   1.910 +
   1.911 +  if ((*write_stream) == NULL) {
   1.912 +    if (length_in_bytes > fixed_buffer_size) {
   1.913 +      (*write_stream) = new CompressedLineNumberWriteStream(length_in_bytes);
   1.914 +    } else {
   1.915 +      (*write_stream) = new CompressedLineNumberWriteStream(
   1.916 +        linenumbertable_buffer, fixed_buffer_size);
   1.917 +    }
   1.918 +  }
   1.919 +
   1.920 +  while (num_entries-- > 0) {
   1.921 +    u2 bci  = cfs->get_u2_fast(); // start_pc
   1.922 +    u2 line = cfs->get_u2_fast(); // line_number
   1.923 +    guarantee_property(bci < code_length,
   1.924 +        "Invalid pc in LineNumberTable in class file %s", CHECK);
   1.925 +    (*write_stream)->write_pair(bci, line);
   1.926 +  }
   1.927 +}
   1.928 +
   1.929 +
   1.930 +// Class file LocalVariableTable elements.
   1.931 +class Classfile_LVT_Element VALUE_OBJ_CLASS_SPEC {
   1.932 + public:
   1.933 +  u2 start_bci;
   1.934 +  u2 length;
   1.935 +  u2 name_cp_index;
   1.936 +  u2 descriptor_cp_index;
   1.937 +  u2 slot;
   1.938 +};
   1.939 +
   1.940 +
   1.941 +class LVT_Hash: public CHeapObj {
   1.942 + public:
   1.943 +  LocalVariableTableElement  *_elem;  // element
   1.944 +  LVT_Hash*                   _next;  // Next entry in hash table
   1.945 +};
   1.946 +
   1.947 +unsigned int hash(LocalVariableTableElement *elem) {
   1.948 +  unsigned int raw_hash = elem->start_bci;
   1.949 +
   1.950 +  raw_hash = elem->length        + raw_hash * 37;
   1.951 +  raw_hash = elem->name_cp_index + raw_hash * 37;
   1.952 +  raw_hash = elem->slot          + raw_hash * 37;
   1.953 +
   1.954 +  return raw_hash % HASH_ROW_SIZE;
   1.955 +}
   1.956 +
   1.957 +void initialize_hashtable(LVT_Hash** table) {
   1.958 +  for (int i = 0; i < HASH_ROW_SIZE; i++) {
   1.959 +    table[i] = NULL;
   1.960 +  }
   1.961 +}
   1.962 +
   1.963 +void clear_hashtable(LVT_Hash** table) {
   1.964 +  for (int i = 0; i < HASH_ROW_SIZE; i++) {
   1.965 +    LVT_Hash* current = table[i];
   1.966 +    LVT_Hash* next;
   1.967 +    while (current != NULL) {
   1.968 +      next = current->_next;
   1.969 +      current->_next = NULL;
   1.970 +      delete(current);
   1.971 +      current = next;
   1.972 +    }
   1.973 +    table[i] = NULL;
   1.974 +  }
   1.975 +}
   1.976 +
   1.977 +LVT_Hash* LVT_lookup(LocalVariableTableElement *elem, int index, LVT_Hash** table) {
   1.978 +  LVT_Hash* entry = table[index];
   1.979 +
   1.980 +  /*
   1.981 +   * 3-tuple start_bci/length/slot has to be unique key,
   1.982 +   * so the following comparison seems to be redundant:
   1.983 +   *       && elem->name_cp_index == entry->_elem->name_cp_index
   1.984 +   */
   1.985 +  while (entry != NULL) {
   1.986 +    if (elem->start_bci           == entry->_elem->start_bci
   1.987 +     && elem->length              == entry->_elem->length
   1.988 +     && elem->name_cp_index       == entry->_elem->name_cp_index
   1.989 +     && elem->slot                == entry->_elem->slot
   1.990 +    ) {
   1.991 +      return entry;
   1.992 +    }
   1.993 +    entry = entry->_next;
   1.994 +  }
   1.995 +  return NULL;
   1.996 +}
   1.997 +
   1.998 +// Return false if the local variable is found in table.
   1.999 +// Return true if no duplicate is found.
  1.1000 +// And local variable is added as a new entry in table.
  1.1001 +bool LVT_put_after_lookup(LocalVariableTableElement *elem, LVT_Hash** table) {
  1.1002 +  // First lookup for duplicates
  1.1003 +  int index = hash(elem);
  1.1004 +  LVT_Hash* entry = LVT_lookup(elem, index, table);
  1.1005 +
  1.1006 +  if (entry != NULL) {
  1.1007 +      return false;
  1.1008 +  }
  1.1009 +  // No duplicate is found, allocate a new entry and fill it.
  1.1010 +  if ((entry = new LVT_Hash()) == NULL) {
  1.1011 +    return false;
  1.1012 +  }
  1.1013 +  entry->_elem = elem;
  1.1014 +
  1.1015 +  // Insert into hash table
  1.1016 +  entry->_next = table[index];
  1.1017 +  table[index] = entry;
  1.1018 +
  1.1019 +  return true;
  1.1020 +}
  1.1021 +
  1.1022 +void copy_lvt_element(Classfile_LVT_Element *src, LocalVariableTableElement *lvt) {
  1.1023 +  lvt->start_bci           = Bytes::get_Java_u2((u1*) &src->start_bci);
  1.1024 +  lvt->length              = Bytes::get_Java_u2((u1*) &src->length);
  1.1025 +  lvt->name_cp_index       = Bytes::get_Java_u2((u1*) &src->name_cp_index);
  1.1026 +  lvt->descriptor_cp_index = Bytes::get_Java_u2((u1*) &src->descriptor_cp_index);
  1.1027 +  lvt->signature_cp_index  = 0;
  1.1028 +  lvt->slot                = Bytes::get_Java_u2((u1*) &src->slot);
  1.1029 +}
  1.1030 +
  1.1031 +// Function is used to parse both attributes:
  1.1032 +//       LocalVariableTable (LVT) and LocalVariableTypeTable (LVTT)
  1.1033 +u2* ClassFileParser::parse_localvariable_table(u4 code_length,
  1.1034 +                                               u2 max_locals,
  1.1035 +                                               u4 code_attribute_length,
  1.1036 +                                               constantPoolHandle cp,
  1.1037 +                                               u2* localvariable_table_length,
  1.1038 +                                               bool isLVTT,
  1.1039 +                                               TRAPS) {
  1.1040 +  ClassFileStream* cfs = stream();
  1.1041 +  const char * tbl_name = (isLVTT) ? "LocalVariableTypeTable" : "LocalVariableTable";
  1.1042 +  *localvariable_table_length = cfs->get_u2(CHECK_NULL);
  1.1043 +  unsigned int size = (*localvariable_table_length) * sizeof(Classfile_LVT_Element) / sizeof(u2);
  1.1044 +  // Verify local variable table attribute has right length
  1.1045 +  if (_need_verify) {
  1.1046 +    guarantee_property(code_attribute_length == (sizeof(*localvariable_table_length) + size * sizeof(u2)),
  1.1047 +                       "%s has wrong length in class file %s", tbl_name, CHECK_NULL);
  1.1048 +  }
  1.1049 +  u2* localvariable_table_start = cfs->get_u2_buffer();
  1.1050 +  assert(localvariable_table_start != NULL, "null local variable table");
  1.1051 +  if (!_need_verify) {
  1.1052 +    cfs->skip_u2_fast(size);
  1.1053 +  } else {
  1.1054 +    cfs->guarantee_more(size * 2, CHECK_NULL);
  1.1055 +    for(int i = 0; i < (*localvariable_table_length); i++) {
  1.1056 +      u2 start_pc = cfs->get_u2_fast();
  1.1057 +      u2 length = cfs->get_u2_fast();
  1.1058 +      u2 name_index = cfs->get_u2_fast();
  1.1059 +      u2 descriptor_index = cfs->get_u2_fast();
  1.1060 +      u2 index = cfs->get_u2_fast();
  1.1061 +      // Assign to a u4 to avoid overflow
  1.1062 +      u4 end_pc = (u4)start_pc + (u4)length;
  1.1063 +
  1.1064 +      if (start_pc >= code_length) {
  1.1065 +        classfile_parse_error(
  1.1066 +          "Invalid start_pc %u in %s in class file %s",
  1.1067 +          start_pc, tbl_name, CHECK_NULL);
  1.1068 +      }
  1.1069 +      if (end_pc > code_length) {
  1.1070 +        classfile_parse_error(
  1.1071 +          "Invalid length %u in %s in class file %s",
  1.1072 +          length, tbl_name, CHECK_NULL);
  1.1073 +      }
  1.1074 +      int cp_size = cp->length();
  1.1075 +      guarantee_property(
  1.1076 +        valid_cp_range(name_index, cp_size) &&
  1.1077 +          cp->tag_at(name_index).is_utf8(),
  1.1078 +        "Name index %u in %s has bad constant type in class file %s",
  1.1079 +        name_index, tbl_name, CHECK_NULL);
  1.1080 +      guarantee_property(
  1.1081 +        valid_cp_range(descriptor_index, cp_size) &&
  1.1082 +          cp->tag_at(descriptor_index).is_utf8(),
  1.1083 +        "Signature index %u in %s has bad constant type in class file %s",
  1.1084 +        descriptor_index, tbl_name, CHECK_NULL);
  1.1085 +
  1.1086 +      symbolHandle name(THREAD, cp->symbol_at(name_index));
  1.1087 +      symbolHandle sig(THREAD, cp->symbol_at(descriptor_index));
  1.1088 +      verify_legal_field_name(name, CHECK_NULL);
  1.1089 +      u2 extra_slot = 0;
  1.1090 +      if (!isLVTT) {
  1.1091 +        verify_legal_field_signature(name, sig, CHECK_NULL);
  1.1092 +
  1.1093 +        // 4894874: check special cases for double and long local variables
  1.1094 +        if (sig() == vmSymbols::type_signature(T_DOUBLE) ||
  1.1095 +            sig() == vmSymbols::type_signature(T_LONG)) {
  1.1096 +          extra_slot = 1;
  1.1097 +        }
  1.1098 +      }
  1.1099 +      guarantee_property((index + extra_slot) < max_locals,
  1.1100 +                          "Invalid index %u in %s in class file %s",
  1.1101 +                          index, tbl_name, CHECK_NULL);
  1.1102 +    }
  1.1103 +  }
  1.1104 +  return localvariable_table_start;
  1.1105 +}
  1.1106 +
  1.1107 +
  1.1108 +void ClassFileParser::parse_type_array(u2 array_length, u4 code_length, u4* u1_index, u4* u2_index,
  1.1109 +                                      u1* u1_array, u2* u2_array, constantPoolHandle cp, TRAPS) {
  1.1110 +  ClassFileStream* cfs = stream();
  1.1111 +  u2 index = 0; // index in the array with long/double occupying two slots
  1.1112 +  u4 i1 = *u1_index;
  1.1113 +  u4 i2 = *u2_index + 1;
  1.1114 +  for(int i = 0; i < array_length; i++) {
  1.1115 +    u1 tag = u1_array[i1++] = cfs->get_u1(CHECK);
  1.1116 +    index++;
  1.1117 +    if (tag == ITEM_Long || tag == ITEM_Double) {
  1.1118 +      index++;
  1.1119 +    } else if (tag == ITEM_Object) {
  1.1120 +      u2 class_index = u2_array[i2++] = cfs->get_u2(CHECK);
  1.1121 +      guarantee_property(valid_cp_range(class_index, cp->length()) &&
  1.1122 +                         cp->tag_at(class_index).is_unresolved_klass(),
  1.1123 +                         "Bad class index %u in StackMap in class file %s",
  1.1124 +                         class_index, CHECK);
  1.1125 +    } else if (tag == ITEM_Uninitialized) {
  1.1126 +      u2 offset = u2_array[i2++] = cfs->get_u2(CHECK);
  1.1127 +      guarantee_property(
  1.1128 +        offset < code_length,
  1.1129 +        "Bad uninitialized type offset %u in StackMap in class file %s",
  1.1130 +        offset, CHECK);
  1.1131 +    } else {
  1.1132 +      guarantee_property(
  1.1133 +        tag <= (u1)ITEM_Uninitialized,
  1.1134 +        "Unknown variable type %u in StackMap in class file %s",
  1.1135 +        tag, CHECK);
  1.1136 +    }
  1.1137 +  }
  1.1138 +  u2_array[*u2_index] = index;
  1.1139 +  *u1_index = i1;
  1.1140 +  *u2_index = i2;
  1.1141 +}
  1.1142 +
  1.1143 +typeArrayOop ClassFileParser::parse_stackmap_table(
  1.1144 +    u4 code_attribute_length, TRAPS) {
  1.1145 +  if (code_attribute_length == 0)
  1.1146 +    return NULL;
  1.1147 +
  1.1148 +  ClassFileStream* cfs = stream();
  1.1149 +  u1* stackmap_table_start = cfs->get_u1_buffer();
  1.1150 +  assert(stackmap_table_start != NULL, "null stackmap table");
  1.1151 +
  1.1152 +  // check code_attribute_length first
  1.1153 +  stream()->skip_u1(code_attribute_length, CHECK_NULL);
  1.1154 +
  1.1155 +  if (!_need_verify && !DumpSharedSpaces) {
  1.1156 +    return NULL;
  1.1157 +  }
  1.1158 +
  1.1159 +  typeArrayOop stackmap_data =
  1.1160 +    oopFactory::new_permanent_byteArray(code_attribute_length, CHECK_NULL);
  1.1161 +
  1.1162 +  stackmap_data->set_length(code_attribute_length);
  1.1163 +  memcpy((void*)stackmap_data->byte_at_addr(0),
  1.1164 +         (void*)stackmap_table_start, code_attribute_length);
  1.1165 +  return stackmap_data;
  1.1166 +}
  1.1167 +
  1.1168 +u2* ClassFileParser::parse_checked_exceptions(u2* checked_exceptions_length,
  1.1169 +                                              u4 method_attribute_length,
  1.1170 +                                              constantPoolHandle cp, TRAPS) {
  1.1171 +  ClassFileStream* cfs = stream();
  1.1172 +  cfs->guarantee_more(2, CHECK_NULL);  // checked_exceptions_length
  1.1173 +  *checked_exceptions_length = cfs->get_u2_fast();
  1.1174 +  unsigned int size = (*checked_exceptions_length) * sizeof(CheckedExceptionElement) / sizeof(u2);
  1.1175 +  u2* checked_exceptions_start = cfs->get_u2_buffer();
  1.1176 +  assert(checked_exceptions_start != NULL, "null checked exceptions");
  1.1177 +  if (!_need_verify) {
  1.1178 +    cfs->skip_u2_fast(size);
  1.1179 +  } else {
  1.1180 +    // Verify each value in the checked exception table
  1.1181 +    u2 checked_exception;
  1.1182 +    u2 len = *checked_exceptions_length;
  1.1183 +    cfs->guarantee_more(2 * len, CHECK_NULL);
  1.1184 +    for (int i = 0; i < len; i++) {
  1.1185 +      checked_exception = cfs->get_u2_fast();
  1.1186 +      check_property(
  1.1187 +        valid_cp_range(checked_exception, cp->length()) &&
  1.1188 +        cp->tag_at(checked_exception).is_klass_reference(),
  1.1189 +        "Exception name has bad type at constant pool %u in class file %s",
  1.1190 +        checked_exception, CHECK_NULL);
  1.1191 +    }
  1.1192 +  }
  1.1193 +  // check exceptions attribute length
  1.1194 +  if (_need_verify) {
  1.1195 +    guarantee_property(method_attribute_length == (sizeof(*checked_exceptions_length) +
  1.1196 +                                                   sizeof(u2) * size),
  1.1197 +                      "Exceptions attribute has wrong length in class file %s", CHECK_NULL);
  1.1198 +  }
  1.1199 +  return checked_exceptions_start;
  1.1200 +}
  1.1201 +
  1.1202 +
  1.1203 +#define MAX_ARGS_SIZE 255
  1.1204 +#define MAX_CODE_SIZE 65535
  1.1205 +#define INITIAL_MAX_LVT_NUMBER 256
  1.1206 +
  1.1207 +// Note: the parse_method below is big and clunky because all parsing of the code and exceptions
  1.1208 +// attribute is inlined. This is curbersome to avoid since we inline most of the parts in the
  1.1209 +// methodOop to save footprint, so we only know the size of the resulting methodOop when the
  1.1210 +// entire method attribute is parsed.
  1.1211 +//
  1.1212 +// The promoted_flags parameter is used to pass relevant access_flags
  1.1213 +// from the method back up to the containing klass. These flag values
  1.1214 +// are added to klass's access_flags.
  1.1215 +
  1.1216 +methodHandle ClassFileParser::parse_method(constantPoolHandle cp, bool is_interface,
  1.1217 +                                           AccessFlags *promoted_flags,
  1.1218 +                                           typeArrayHandle* method_annotations,
  1.1219 +                                           typeArrayHandle* method_parameter_annotations,
  1.1220 +                                           typeArrayHandle* method_default_annotations,
  1.1221 +                                           TRAPS) {
  1.1222 +  ClassFileStream* cfs = stream();
  1.1223 +  methodHandle nullHandle;
  1.1224 +  ResourceMark rm(THREAD);
  1.1225 +  // Parse fixed parts
  1.1226 +  cfs->guarantee_more(8, CHECK_(nullHandle)); // access_flags, name_index, descriptor_index, attributes_count
  1.1227 +
  1.1228 +  int flags = cfs->get_u2_fast();
  1.1229 +  u2 name_index = cfs->get_u2_fast();
  1.1230 +  int cp_size = cp->length();
  1.1231 +  check_property(
  1.1232 +    valid_cp_range(name_index, cp_size) &&
  1.1233 +      cp->tag_at(name_index).is_utf8(),
  1.1234 +    "Illegal constant pool index %u for method name in class file %s",
  1.1235 +    name_index, CHECK_(nullHandle));
  1.1236 +  symbolHandle name(THREAD, cp->symbol_at(name_index));
  1.1237 +  verify_legal_method_name(name, CHECK_(nullHandle));
  1.1238 +
  1.1239 +  u2 signature_index = cfs->get_u2_fast();
  1.1240 +  guarantee_property(
  1.1241 +    valid_cp_range(signature_index, cp_size) &&
  1.1242 +      cp->tag_at(signature_index).is_utf8(),
  1.1243 +    "Illegal constant pool index %u for method signature in class file %s",
  1.1244 +    signature_index, CHECK_(nullHandle));
  1.1245 +  symbolHandle signature(THREAD, cp->symbol_at(signature_index));
  1.1246 +
  1.1247 +  AccessFlags access_flags;
  1.1248 +  if (name == vmSymbols::class_initializer_name()) {
  1.1249 +    // We ignore the access flags for a class initializer. (JVM Spec. p. 116)
  1.1250 +    flags = JVM_ACC_STATIC;
  1.1251 +  } else {
  1.1252 +    verify_legal_method_modifiers(flags, is_interface, name, CHECK_(nullHandle));
  1.1253 +  }
  1.1254 +
  1.1255 +  int args_size = -1;  // only used when _need_verify is true
  1.1256 +  if (_need_verify) {
  1.1257 +    args_size = ((flags & JVM_ACC_STATIC) ? 0 : 1) +
  1.1258 +                 verify_legal_method_signature(name, signature, CHECK_(nullHandle));
  1.1259 +    if (args_size > MAX_ARGS_SIZE) {
  1.1260 +      classfile_parse_error("Too many arguments in method signature in class file %s", CHECK_(nullHandle));
  1.1261 +    }
  1.1262 +  }
  1.1263 +
  1.1264 +  access_flags.set_flags(flags & JVM_RECOGNIZED_METHOD_MODIFIERS);
  1.1265 +
  1.1266 +  // Default values for code and exceptions attribute elements
  1.1267 +  u2 max_stack = 0;
  1.1268 +  u2 max_locals = 0;
  1.1269 +  u4 code_length = 0;
  1.1270 +  u1* code_start = 0;
  1.1271 +  u2 exception_table_length = 0;
  1.1272 +  typeArrayHandle exception_handlers(THREAD, Universe::the_empty_int_array());
  1.1273 +  u2 checked_exceptions_length = 0;
  1.1274 +  u2* checked_exceptions_start = NULL;
  1.1275 +  CompressedLineNumberWriteStream* linenumber_table = NULL;
  1.1276 +  int linenumber_table_length = 0;
  1.1277 +  int total_lvt_length = 0;
  1.1278 +  u2 lvt_cnt = 0;
  1.1279 +  u2 lvtt_cnt = 0;
  1.1280 +  bool lvt_allocated = false;
  1.1281 +  u2 max_lvt_cnt = INITIAL_MAX_LVT_NUMBER;
  1.1282 +  u2 max_lvtt_cnt = INITIAL_MAX_LVT_NUMBER;
  1.1283 +  u2* localvariable_table_length;
  1.1284 +  u2** localvariable_table_start;
  1.1285 +  u2* localvariable_type_table_length;
  1.1286 +  u2** localvariable_type_table_start;
  1.1287 +  bool parsed_code_attribute = false;
  1.1288 +  bool parsed_checked_exceptions_attribute = false;
  1.1289 +  bool parsed_stackmap_attribute = false;
  1.1290 +  // stackmap attribute - JDK1.5
  1.1291 +  typeArrayHandle stackmap_data;
  1.1292 +  u2 generic_signature_index = 0;
  1.1293 +  u1* runtime_visible_annotations = NULL;
  1.1294 +  int runtime_visible_annotations_length = 0;
  1.1295 +  u1* runtime_invisible_annotations = NULL;
  1.1296 +  int runtime_invisible_annotations_length = 0;
  1.1297 +  u1* runtime_visible_parameter_annotations = NULL;
  1.1298 +  int runtime_visible_parameter_annotations_length = 0;
  1.1299 +  u1* runtime_invisible_parameter_annotations = NULL;
  1.1300 +  int runtime_invisible_parameter_annotations_length = 0;
  1.1301 +  u1* annotation_default = NULL;
  1.1302 +  int annotation_default_length = 0;
  1.1303 +
  1.1304 +  // Parse code and exceptions attribute
  1.1305 +  u2 method_attributes_count = cfs->get_u2_fast();
  1.1306 +  while (method_attributes_count--) {
  1.1307 +    cfs->guarantee_more(6, CHECK_(nullHandle));  // method_attribute_name_index, method_attribute_length
  1.1308 +    u2 method_attribute_name_index = cfs->get_u2_fast();
  1.1309 +    u4 method_attribute_length = cfs->get_u4_fast();
  1.1310 +    check_property(
  1.1311 +      valid_cp_range(method_attribute_name_index, cp_size) &&
  1.1312 +        cp->tag_at(method_attribute_name_index).is_utf8(),
  1.1313 +      "Invalid method attribute name index %u in class file %s",
  1.1314 +      method_attribute_name_index, CHECK_(nullHandle));
  1.1315 +
  1.1316 +    symbolOop method_attribute_name = cp->symbol_at(method_attribute_name_index);
  1.1317 +    if (method_attribute_name == vmSymbols::tag_code()) {
  1.1318 +      // Parse Code attribute
  1.1319 +      if (_need_verify) {
  1.1320 +        guarantee_property(!access_flags.is_native() && !access_flags.is_abstract(),
  1.1321 +                        "Code attribute in native or abstract methods in class file %s",
  1.1322 +                         CHECK_(nullHandle));
  1.1323 +      }
  1.1324 +      if (parsed_code_attribute) {
  1.1325 +        classfile_parse_error("Multiple Code attributes in class file %s", CHECK_(nullHandle));
  1.1326 +      }
  1.1327 +      parsed_code_attribute = true;
  1.1328 +
  1.1329 +      // Stack size, locals size, and code size
  1.1330 +      if (_major_version == 45 && _minor_version <= 2) {
  1.1331 +        cfs->guarantee_more(4, CHECK_(nullHandle));
  1.1332 +        max_stack = cfs->get_u1_fast();
  1.1333 +        max_locals = cfs->get_u1_fast();
  1.1334 +        code_length = cfs->get_u2_fast();
  1.1335 +      } else {
  1.1336 +        cfs->guarantee_more(8, CHECK_(nullHandle));
  1.1337 +        max_stack = cfs->get_u2_fast();
  1.1338 +        max_locals = cfs->get_u2_fast();
  1.1339 +        code_length = cfs->get_u4_fast();
  1.1340 +      }
  1.1341 +      if (_need_verify) {
  1.1342 +        guarantee_property(args_size <= max_locals,
  1.1343 +                           "Arguments can't fit into locals in class file %s", CHECK_(nullHandle));
  1.1344 +        guarantee_property(code_length > 0 && code_length <= MAX_CODE_SIZE,
  1.1345 +                           "Invalid method Code length %u in class file %s",
  1.1346 +                           code_length, CHECK_(nullHandle));
  1.1347 +      }
  1.1348 +      // Code pointer
  1.1349 +      code_start = cfs->get_u1_buffer();
  1.1350 +      assert(code_start != NULL, "null code start");
  1.1351 +      cfs->guarantee_more(code_length, CHECK_(nullHandle));
  1.1352 +      cfs->skip_u1_fast(code_length);
  1.1353 +
  1.1354 +      // Exception handler table
  1.1355 +      cfs->guarantee_more(2, CHECK_(nullHandle));  // exception_table_length
  1.1356 +      exception_table_length = cfs->get_u2_fast();
  1.1357 +      if (exception_table_length > 0) {
  1.1358 +        exception_handlers =
  1.1359 +              parse_exception_table(code_length, exception_table_length, cp, CHECK_(nullHandle));
  1.1360 +      }
  1.1361 +
  1.1362 +      // Parse additional attributes in code attribute
  1.1363 +      cfs->guarantee_more(2, CHECK_(nullHandle));  // code_attributes_count
  1.1364 +      u2 code_attributes_count = cfs->get_u2_fast();
  1.1365 +      unsigned int calculated_attribute_length = sizeof(max_stack) +
  1.1366 +                                                 sizeof(max_locals) +
  1.1367 +                                                 sizeof(code_length) +
  1.1368 +                                                 code_length +
  1.1369 +                                                 sizeof(exception_table_length) +
  1.1370 +                                                 sizeof(code_attributes_count) +
  1.1371 +                                                 exception_table_length*(sizeof(u2) /* start_pc */+
  1.1372 +                                                                         sizeof(u2) /* end_pc */  +
  1.1373 +                                                                         sizeof(u2) /* handler_pc */ +
  1.1374 +                                                                         sizeof(u2) /* catch_type_index */);
  1.1375 +
  1.1376 +      while (code_attributes_count--) {
  1.1377 +        cfs->guarantee_more(6, CHECK_(nullHandle));  // code_attribute_name_index, code_attribute_length
  1.1378 +        u2 code_attribute_name_index = cfs->get_u2_fast();
  1.1379 +        u4 code_attribute_length = cfs->get_u4_fast();
  1.1380 +        calculated_attribute_length += code_attribute_length +
  1.1381 +                                       sizeof(code_attribute_name_index) +
  1.1382 +                                       sizeof(code_attribute_length);
  1.1383 +        check_property(valid_cp_range(code_attribute_name_index, cp_size) &&
  1.1384 +                       cp->tag_at(code_attribute_name_index).is_utf8(),
  1.1385 +                       "Invalid code attribute name index %u in class file %s",
  1.1386 +                       code_attribute_name_index,
  1.1387 +                       CHECK_(nullHandle));
  1.1388 +        if (LoadLineNumberTables &&
  1.1389 +            cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_line_number_table()) {
  1.1390 +          // Parse and compress line number table
  1.1391 +          parse_linenumber_table(code_attribute_length, code_length,
  1.1392 +            &linenumber_table, CHECK_(nullHandle));
  1.1393 +
  1.1394 +        } else if (LoadLocalVariableTables &&
  1.1395 +                   cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_local_variable_table()) {
  1.1396 +          // Parse local variable table
  1.1397 +          if (!lvt_allocated) {
  1.1398 +            localvariable_table_length = NEW_RESOURCE_ARRAY_IN_THREAD(
  1.1399 +              THREAD, u2,  INITIAL_MAX_LVT_NUMBER);
  1.1400 +            localvariable_table_start = NEW_RESOURCE_ARRAY_IN_THREAD(
  1.1401 +              THREAD, u2*, INITIAL_MAX_LVT_NUMBER);
  1.1402 +            localvariable_type_table_length = NEW_RESOURCE_ARRAY_IN_THREAD(
  1.1403 +              THREAD, u2,  INITIAL_MAX_LVT_NUMBER);
  1.1404 +            localvariable_type_table_start = NEW_RESOURCE_ARRAY_IN_THREAD(
  1.1405 +              THREAD, u2*, INITIAL_MAX_LVT_NUMBER);
  1.1406 +            lvt_allocated = true;
  1.1407 +          }
  1.1408 +          if (lvt_cnt == max_lvt_cnt) {
  1.1409 +            max_lvt_cnt <<= 1;
  1.1410 +            REALLOC_RESOURCE_ARRAY(u2, localvariable_table_length, lvt_cnt, max_lvt_cnt);
  1.1411 +            REALLOC_RESOURCE_ARRAY(u2*, localvariable_table_start, lvt_cnt, max_lvt_cnt);
  1.1412 +          }
  1.1413 +          localvariable_table_start[lvt_cnt] =
  1.1414 +            parse_localvariable_table(code_length,
  1.1415 +                                      max_locals,
  1.1416 +                                      code_attribute_length,
  1.1417 +                                      cp,
  1.1418 +                                      &localvariable_table_length[lvt_cnt],
  1.1419 +                                      false,    // is not LVTT
  1.1420 +                                      CHECK_(nullHandle));
  1.1421 +          total_lvt_length += localvariable_table_length[lvt_cnt];
  1.1422 +          lvt_cnt++;
  1.1423 +        } else if (LoadLocalVariableTypeTables &&
  1.1424 +                   _major_version >= JAVA_1_5_VERSION &&
  1.1425 +                   cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_local_variable_type_table()) {
  1.1426 +          if (!lvt_allocated) {
  1.1427 +            localvariable_table_length = NEW_RESOURCE_ARRAY_IN_THREAD(
  1.1428 +              THREAD, u2,  INITIAL_MAX_LVT_NUMBER);
  1.1429 +            localvariable_table_start = NEW_RESOURCE_ARRAY_IN_THREAD(
  1.1430 +              THREAD, u2*, INITIAL_MAX_LVT_NUMBER);
  1.1431 +            localvariable_type_table_length = NEW_RESOURCE_ARRAY_IN_THREAD(
  1.1432 +              THREAD, u2,  INITIAL_MAX_LVT_NUMBER);
  1.1433 +            localvariable_type_table_start = NEW_RESOURCE_ARRAY_IN_THREAD(
  1.1434 +              THREAD, u2*, INITIAL_MAX_LVT_NUMBER);
  1.1435 +            lvt_allocated = true;
  1.1436 +          }
  1.1437 +          // Parse local variable type table
  1.1438 +          if (lvtt_cnt == max_lvtt_cnt) {
  1.1439 +            max_lvtt_cnt <<= 1;
  1.1440 +            REALLOC_RESOURCE_ARRAY(u2, localvariable_type_table_length, lvtt_cnt, max_lvtt_cnt);
  1.1441 +            REALLOC_RESOURCE_ARRAY(u2*, localvariable_type_table_start, lvtt_cnt, max_lvtt_cnt);
  1.1442 +          }
  1.1443 +          localvariable_type_table_start[lvtt_cnt] =
  1.1444 +            parse_localvariable_table(code_length,
  1.1445 +                                      max_locals,
  1.1446 +                                      code_attribute_length,
  1.1447 +                                      cp,
  1.1448 +                                      &localvariable_type_table_length[lvtt_cnt],
  1.1449 +                                      true,     // is LVTT
  1.1450 +                                      CHECK_(nullHandle));
  1.1451 +          lvtt_cnt++;
  1.1452 +        } else if (UseSplitVerifier &&
  1.1453 +                   _major_version >= Verifier::STACKMAP_ATTRIBUTE_MAJOR_VERSION &&
  1.1454 +                   cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_stack_map_table()) {
  1.1455 +          // Stack map is only needed by the new verifier in JDK1.5.
  1.1456 +          if (parsed_stackmap_attribute) {
  1.1457 +            classfile_parse_error("Multiple StackMapTable attributes in class file %s", CHECK_(nullHandle));
  1.1458 +          }
  1.1459 +          typeArrayOop sm =
  1.1460 +            parse_stackmap_table(code_attribute_length, CHECK_(nullHandle));
  1.1461 +          stackmap_data = typeArrayHandle(THREAD, sm);
  1.1462 +          parsed_stackmap_attribute = true;
  1.1463 +        } else {
  1.1464 +          // Skip unknown attributes
  1.1465 +          cfs->skip_u1(code_attribute_length, CHECK_(nullHandle));
  1.1466 +        }
  1.1467 +      }
  1.1468 +      // check method attribute length
  1.1469 +      if (_need_verify) {
  1.1470 +        guarantee_property(method_attribute_length == calculated_attribute_length,
  1.1471 +                           "Code segment has wrong length in class file %s", CHECK_(nullHandle));
  1.1472 +      }
  1.1473 +    } else if (method_attribute_name == vmSymbols::tag_exceptions()) {
  1.1474 +      // Parse Exceptions attribute
  1.1475 +      if (parsed_checked_exceptions_attribute) {
  1.1476 +        classfile_parse_error("Multiple Exceptions attributes in class file %s", CHECK_(nullHandle));
  1.1477 +      }
  1.1478 +      parsed_checked_exceptions_attribute = true;
  1.1479 +      checked_exceptions_start =
  1.1480 +            parse_checked_exceptions(&checked_exceptions_length,
  1.1481 +                                     method_attribute_length,
  1.1482 +                                     cp, CHECK_(nullHandle));
  1.1483 +    } else if (method_attribute_name == vmSymbols::tag_synthetic()) {
  1.1484 +      if (method_attribute_length != 0) {
  1.1485 +        classfile_parse_error(
  1.1486 +          "Invalid Synthetic method attribute length %u in class file %s",
  1.1487 +          method_attribute_length, CHECK_(nullHandle));
  1.1488 +      }
  1.1489 +      // Should we check that there hasn't already been a synthetic attribute?
  1.1490 +      access_flags.set_is_synthetic();
  1.1491 +    } else if (method_attribute_name == vmSymbols::tag_deprecated()) { // 4276120
  1.1492 +      if (method_attribute_length != 0) {
  1.1493 +        classfile_parse_error(
  1.1494 +          "Invalid Deprecated method attribute length %u in class file %s",
  1.1495 +          method_attribute_length, CHECK_(nullHandle));
  1.1496 +      }
  1.1497 +    } else if (_major_version >= JAVA_1_5_VERSION) {
  1.1498 +      if (method_attribute_name == vmSymbols::tag_signature()) {
  1.1499 +        if (method_attribute_length != 2) {
  1.1500 +          classfile_parse_error(
  1.1501 +            "Invalid Signature attribute length %u in class file %s",
  1.1502 +            method_attribute_length, CHECK_(nullHandle));
  1.1503 +        }
  1.1504 +        cfs->guarantee_more(2, CHECK_(nullHandle));  // generic_signature_index
  1.1505 +        generic_signature_index = cfs->get_u2_fast();
  1.1506 +      } else if (method_attribute_name == vmSymbols::tag_runtime_visible_annotations()) {
  1.1507 +        runtime_visible_annotations_length = method_attribute_length;
  1.1508 +        runtime_visible_annotations = cfs->get_u1_buffer();
  1.1509 +        assert(runtime_visible_annotations != NULL, "null visible annotations");
  1.1510 +        cfs->skip_u1(runtime_visible_annotations_length, CHECK_(nullHandle));
  1.1511 +      } else if (PreserveAllAnnotations && method_attribute_name == vmSymbols::tag_runtime_invisible_annotations()) {
  1.1512 +        runtime_invisible_annotations_length = method_attribute_length;
  1.1513 +        runtime_invisible_annotations = cfs->get_u1_buffer();
  1.1514 +        assert(runtime_invisible_annotations != NULL, "null invisible annotations");
  1.1515 +        cfs->skip_u1(runtime_invisible_annotations_length, CHECK_(nullHandle));
  1.1516 +      } else if (method_attribute_name == vmSymbols::tag_runtime_visible_parameter_annotations()) {
  1.1517 +        runtime_visible_parameter_annotations_length = method_attribute_length;
  1.1518 +        runtime_visible_parameter_annotations = cfs->get_u1_buffer();
  1.1519 +        assert(runtime_visible_parameter_annotations != NULL, "null visible parameter annotations");
  1.1520 +        cfs->skip_u1(runtime_visible_parameter_annotations_length, CHECK_(nullHandle));
  1.1521 +      } else if (PreserveAllAnnotations && method_attribute_name == vmSymbols::tag_runtime_invisible_parameter_annotations()) {
  1.1522 +        runtime_invisible_parameter_annotations_length = method_attribute_length;
  1.1523 +        runtime_invisible_parameter_annotations = cfs->get_u1_buffer();
  1.1524 +        assert(runtime_invisible_parameter_annotations != NULL, "null invisible parameter annotations");
  1.1525 +        cfs->skip_u1(runtime_invisible_parameter_annotations_length, CHECK_(nullHandle));
  1.1526 +      } else if (method_attribute_name == vmSymbols::tag_annotation_default()) {
  1.1527 +        annotation_default_length = method_attribute_length;
  1.1528 +        annotation_default = cfs->get_u1_buffer();
  1.1529 +        assert(annotation_default != NULL, "null annotation default");
  1.1530 +        cfs->skip_u1(annotation_default_length, CHECK_(nullHandle));
  1.1531 +      } else {
  1.1532 +        // Skip unknown attributes
  1.1533 +        cfs->skip_u1(method_attribute_length, CHECK_(nullHandle));
  1.1534 +      }
  1.1535 +    } else {
  1.1536 +      // Skip unknown attributes
  1.1537 +      cfs->skip_u1(method_attribute_length, CHECK_(nullHandle));
  1.1538 +    }
  1.1539 +  }
  1.1540 +
  1.1541 +  if (linenumber_table != NULL) {
  1.1542 +    linenumber_table->write_terminator();
  1.1543 +    linenumber_table_length = linenumber_table->position();
  1.1544 +  }
  1.1545 +
  1.1546 +  // Make sure there's at least one Code attribute in non-native/non-abstract method
  1.1547 +  if (_need_verify) {
  1.1548 +    guarantee_property(access_flags.is_native() || access_flags.is_abstract() || parsed_code_attribute,
  1.1549 +                      "Absent Code attribute in method that is not native or abstract in class file %s", CHECK_(nullHandle));
  1.1550 +  }
  1.1551 +
  1.1552 +  // All sizing information for a methodOop is finally available, now create it
  1.1553 +  methodOop m_oop  = oopFactory::new_method(
  1.1554 +    code_length, access_flags, linenumber_table_length,
  1.1555 +    total_lvt_length, checked_exceptions_length, CHECK_(nullHandle));
  1.1556 +  methodHandle m (THREAD, m_oop);
  1.1557 +
  1.1558 +  ClassLoadingService::add_class_method_size(m_oop->size()*HeapWordSize);
  1.1559 +
  1.1560 +  // Fill in information from fixed part (access_flags already set)
  1.1561 +  m->set_constants(cp());
  1.1562 +  m->set_name_index(name_index);
  1.1563 +  m->set_signature_index(signature_index);
  1.1564 +  m->set_generic_signature_index(generic_signature_index);
  1.1565 +#ifdef CC_INTERP
  1.1566 +  // hmm is there a gc issue here??
  1.1567 +  ResultTypeFinder rtf(cp->symbol_at(signature_index));
  1.1568 +  m->set_result_index(rtf.type());
  1.1569 +#endif
  1.1570 +
  1.1571 +  if (args_size >= 0) {
  1.1572 +    m->set_size_of_parameters(args_size);
  1.1573 +  } else {
  1.1574 +    m->compute_size_of_parameters(THREAD);
  1.1575 +  }
  1.1576 +#ifdef ASSERT
  1.1577 +  if (args_size >= 0) {
  1.1578 +    m->compute_size_of_parameters(THREAD);
  1.1579 +    assert(args_size == m->size_of_parameters(), "");
  1.1580 +  }
  1.1581 +#endif
  1.1582 +
  1.1583 +  // Fill in code attribute information
  1.1584 +  m->set_max_stack(max_stack);
  1.1585 +  m->set_max_locals(max_locals);
  1.1586 +  m->constMethod()->set_stackmap_data(stackmap_data());
  1.1587 +
  1.1588 +  /**
  1.1589 +   * The exception_table field is the flag used to indicate
  1.1590 +   * that the methodOop and it's associated constMethodOop are partially
  1.1591 +   * initialized and thus are exempt from pre/post GC verification.  Once
  1.1592 +   * the field is set, the oops are considered fully initialized so make
  1.1593 +   * sure that the oops can pass verification when this field is set.
  1.1594 +   */
  1.1595 +  m->set_exception_table(exception_handlers());
  1.1596 +
  1.1597 +  // Copy byte codes
  1.1598 +  if (code_length > 0) {
  1.1599 +    memcpy(m->code_base(), code_start, code_length);
  1.1600 +  }
  1.1601 +
  1.1602 +  // Copy line number table
  1.1603 +  if (linenumber_table != NULL) {
  1.1604 +    memcpy(m->compressed_linenumber_table(),
  1.1605 +           linenumber_table->buffer(), linenumber_table_length);
  1.1606 +  }
  1.1607 +
  1.1608 +  // Copy checked exceptions
  1.1609 +  if (checked_exceptions_length > 0) {
  1.1610 +    int size = checked_exceptions_length * sizeof(CheckedExceptionElement) / sizeof(u2);
  1.1611 +    copy_u2_with_conversion((u2*) m->checked_exceptions_start(), checked_exceptions_start, size);
  1.1612 +  }
  1.1613 +
  1.1614 +  /* Copy class file LVT's/LVTT's into the HotSpot internal LVT.
  1.1615 +   *
  1.1616 +   * Rules for LVT's and LVTT's are:
  1.1617 +   *   - There can be any number of LVT's and LVTT's.
  1.1618 +   *   - If there are n LVT's, it is the same as if there was just
  1.1619 +   *     one LVT containing all the entries from the n LVT's.
  1.1620 +   *   - There may be no more than one LVT entry per local variable.
  1.1621 +   *     Two LVT entries are 'equal' if these fields are the same:
  1.1622 +   *        start_pc, length, name, slot
  1.1623 +   *   - There may be no more than one LVTT entry per each LVT entry.
  1.1624 +   *     Each LVTT entry has to match some LVT entry.
  1.1625 +   *   - HotSpot internal LVT keeps natural ordering of class file LVT entries.
  1.1626 +   */
  1.1627 +  if (total_lvt_length > 0) {
  1.1628 +    int tbl_no, idx;
  1.1629 +
  1.1630 +    promoted_flags->set_has_localvariable_table();
  1.1631 +
  1.1632 +    LVT_Hash** lvt_Hash = NEW_RESOURCE_ARRAY(LVT_Hash*, HASH_ROW_SIZE);
  1.1633 +    initialize_hashtable(lvt_Hash);
  1.1634 +
  1.1635 +    // To fill LocalVariableTable in
  1.1636 +    Classfile_LVT_Element*  cf_lvt;
  1.1637 +    LocalVariableTableElement* lvt = m->localvariable_table_start();
  1.1638 +
  1.1639 +    for (tbl_no = 0; tbl_no < lvt_cnt; tbl_no++) {
  1.1640 +      cf_lvt = (Classfile_LVT_Element *) localvariable_table_start[tbl_no];
  1.1641 +      for (idx = 0; idx < localvariable_table_length[tbl_no]; idx++, lvt++) {
  1.1642 +        copy_lvt_element(&cf_lvt[idx], lvt);
  1.1643 +        // If no duplicates, add LVT elem in hashtable lvt_Hash.
  1.1644 +        if (LVT_put_after_lookup(lvt, lvt_Hash) == false
  1.1645 +          && _need_verify
  1.1646 +          && _major_version >= JAVA_1_5_VERSION ) {
  1.1647 +          clear_hashtable(lvt_Hash);
  1.1648 +          classfile_parse_error("Duplicated LocalVariableTable attribute "
  1.1649 +                                "entry for '%s' in class file %s",
  1.1650 +                                 cp->symbol_at(lvt->name_cp_index)->as_utf8(),
  1.1651 +                                 CHECK_(nullHandle));
  1.1652 +        }
  1.1653 +      }
  1.1654 +    }
  1.1655 +
  1.1656 +    // To merge LocalVariableTable and LocalVariableTypeTable
  1.1657 +    Classfile_LVT_Element* cf_lvtt;
  1.1658 +    LocalVariableTableElement lvtt_elem;
  1.1659 +
  1.1660 +    for (tbl_no = 0; tbl_no < lvtt_cnt; tbl_no++) {
  1.1661 +      cf_lvtt = (Classfile_LVT_Element *) localvariable_type_table_start[tbl_no];
  1.1662 +      for (idx = 0; idx < localvariable_type_table_length[tbl_no]; idx++) {
  1.1663 +        copy_lvt_element(&cf_lvtt[idx], &lvtt_elem);
  1.1664 +        int index = hash(&lvtt_elem);
  1.1665 +        LVT_Hash* entry = LVT_lookup(&lvtt_elem, index, lvt_Hash);
  1.1666 +        if (entry == NULL) {
  1.1667 +          if (_need_verify) {
  1.1668 +            clear_hashtable(lvt_Hash);
  1.1669 +            classfile_parse_error("LVTT entry for '%s' in class file %s "
  1.1670 +                                  "does not match any LVT entry",
  1.1671 +                                   cp->symbol_at(lvtt_elem.name_cp_index)->as_utf8(),
  1.1672 +                                   CHECK_(nullHandle));
  1.1673 +          }
  1.1674 +        } else if (entry->_elem->signature_cp_index != 0 && _need_verify) {
  1.1675 +          clear_hashtable(lvt_Hash);
  1.1676 +          classfile_parse_error("Duplicated LocalVariableTypeTable attribute "
  1.1677 +                                "entry for '%s' in class file %s",
  1.1678 +                                 cp->symbol_at(lvtt_elem.name_cp_index)->as_utf8(),
  1.1679 +                                 CHECK_(nullHandle));
  1.1680 +        } else {
  1.1681 +          // to add generic signatures into LocalVariableTable
  1.1682 +          entry->_elem->signature_cp_index = lvtt_elem.descriptor_cp_index;
  1.1683 +        }
  1.1684 +      }
  1.1685 +    }
  1.1686 +    clear_hashtable(lvt_Hash);
  1.1687 +  }
  1.1688 +
  1.1689 +  *method_annotations = assemble_annotations(runtime_visible_annotations,
  1.1690 +                                             runtime_visible_annotations_length,
  1.1691 +                                             runtime_invisible_annotations,
  1.1692 +                                             runtime_invisible_annotations_length,
  1.1693 +                                             CHECK_(nullHandle));
  1.1694 +  *method_parameter_annotations = assemble_annotations(runtime_visible_parameter_annotations,
  1.1695 +                                                       runtime_visible_parameter_annotations_length,
  1.1696 +                                                       runtime_invisible_parameter_annotations,
  1.1697 +                                                       runtime_invisible_parameter_annotations_length,
  1.1698 +                                                       CHECK_(nullHandle));
  1.1699 +  *method_default_annotations = assemble_annotations(annotation_default,
  1.1700 +                                                     annotation_default_length,
  1.1701 +                                                     NULL,
  1.1702 +                                                     0,
  1.1703 +                                                     CHECK_(nullHandle));
  1.1704 +
  1.1705 +  if (name() == vmSymbols::finalize_method_name() &&
  1.1706 +      signature() == vmSymbols::void_method_signature()) {
  1.1707 +    if (m->is_empty_method()) {
  1.1708 +      _has_empty_finalizer = true;
  1.1709 +    } else {
  1.1710 +      _has_finalizer = true;
  1.1711 +    }
  1.1712 +  }
  1.1713 +  if (name() == vmSymbols::object_initializer_name() &&
  1.1714 +      signature() == vmSymbols::void_method_signature() &&
  1.1715 +      m->is_vanilla_constructor()) {
  1.1716 +    _has_vanilla_constructor = true;
  1.1717 +  }
  1.1718 +
  1.1719 +  return m;
  1.1720 +}
  1.1721 +
  1.1722 +
  1.1723 +// The promoted_flags parameter is used to pass relevant access_flags
  1.1724 +// from the methods back up to the containing klass. These flag values
  1.1725 +// are added to klass's access_flags.
  1.1726 +
  1.1727 +objArrayHandle ClassFileParser::parse_methods(constantPoolHandle cp, bool is_interface,
  1.1728 +                                              AccessFlags* promoted_flags,
  1.1729 +                                              bool* has_final_method,
  1.1730 +                                              objArrayOop* methods_annotations_oop,
  1.1731 +                                              objArrayOop* methods_parameter_annotations_oop,
  1.1732 +                                              objArrayOop* methods_default_annotations_oop,
  1.1733 +                                              TRAPS) {
  1.1734 +  ClassFileStream* cfs = stream();
  1.1735 +  objArrayHandle nullHandle;
  1.1736 +  typeArrayHandle method_annotations;
  1.1737 +  typeArrayHandle method_parameter_annotations;
  1.1738 +  typeArrayHandle method_default_annotations;
  1.1739 +  cfs->guarantee_more(2, CHECK_(nullHandle));  // length
  1.1740 +  u2 length = cfs->get_u2_fast();
  1.1741 +  if (length == 0) {
  1.1742 +    return objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  1.1743 +  } else {
  1.1744 +    objArrayOop m = oopFactory::new_system_objArray(length, CHECK_(nullHandle));
  1.1745 +    objArrayHandle methods(THREAD, m);
  1.1746 +    HandleMark hm(THREAD);
  1.1747 +    objArrayHandle methods_annotations;
  1.1748 +    objArrayHandle methods_parameter_annotations;
  1.1749 +    objArrayHandle methods_default_annotations;
  1.1750 +    for (int index = 0; index < length; index++) {
  1.1751 +      methodHandle method = parse_method(cp, is_interface,
  1.1752 +                                         promoted_flags,
  1.1753 +                                         &method_annotations,
  1.1754 +                                         &method_parameter_annotations,
  1.1755 +                                         &method_default_annotations,
  1.1756 +                                         CHECK_(nullHandle));
  1.1757 +      if (method->is_final()) {
  1.1758 +        *has_final_method = true;
  1.1759 +      }
  1.1760 +      methods->obj_at_put(index, method());
  1.1761 +      if (method_annotations.not_null()) {
  1.1762 +        if (methods_annotations.is_null()) {
  1.1763 +          objArrayOop md = oopFactory::new_system_objArray(length, CHECK_(nullHandle));
  1.1764 +          methods_annotations = objArrayHandle(THREAD, md);
  1.1765 +        }
  1.1766 +        methods_annotations->obj_at_put(index, method_annotations());
  1.1767 +      }
  1.1768 +      if (method_parameter_annotations.not_null()) {
  1.1769 +        if (methods_parameter_annotations.is_null()) {
  1.1770 +          objArrayOop md = oopFactory::new_system_objArray(length, CHECK_(nullHandle));
  1.1771 +          methods_parameter_annotations = objArrayHandle(THREAD, md);
  1.1772 +        }
  1.1773 +        methods_parameter_annotations->obj_at_put(index, method_parameter_annotations());
  1.1774 +      }
  1.1775 +      if (method_default_annotations.not_null()) {
  1.1776 +        if (methods_default_annotations.is_null()) {
  1.1777 +          objArrayOop md = oopFactory::new_system_objArray(length, CHECK_(nullHandle));
  1.1778 +          methods_default_annotations = objArrayHandle(THREAD, md);
  1.1779 +        }
  1.1780 +        methods_default_annotations->obj_at_put(index, method_default_annotations());
  1.1781 +      }
  1.1782 +    }
  1.1783 +    if (_need_verify && length > 1) {
  1.1784 +      // Check duplicated methods
  1.1785 +      ResourceMark rm(THREAD);
  1.1786 +      NameSigHash** names_and_sigs = NEW_RESOURCE_ARRAY_IN_THREAD(
  1.1787 +        THREAD, NameSigHash*, HASH_ROW_SIZE);
  1.1788 +      initialize_hashtable(names_and_sigs);
  1.1789 +      bool dup = false;
  1.1790 +      {
  1.1791 +        debug_only(No_Safepoint_Verifier nsv;)
  1.1792 +        for (int i = 0; i < length; i++) {
  1.1793 +          methodOop m = (methodOop)methods->obj_at(i);
  1.1794 +          // If no duplicates, add name/signature in hashtable names_and_sigs.
  1.1795 +          if (!put_after_lookup(m->name(), m->signature(), names_and_sigs)) {
  1.1796 +            dup = true;
  1.1797 +            break;
  1.1798 +          }
  1.1799 +        }
  1.1800 +      }
  1.1801 +      if (dup) {
  1.1802 +        classfile_parse_error("Duplicate method name&signature in class file %s",
  1.1803 +                              CHECK_(nullHandle));
  1.1804 +      }
  1.1805 +    }
  1.1806 +
  1.1807 +    *methods_annotations_oop = methods_annotations();
  1.1808 +    *methods_parameter_annotations_oop = methods_parameter_annotations();
  1.1809 +    *methods_default_annotations_oop = methods_default_annotations();
  1.1810 +
  1.1811 +    return methods;
  1.1812 +  }
  1.1813 +}
  1.1814 +
  1.1815 +
  1.1816 +typeArrayHandle ClassFileParser::sort_methods(objArrayHandle methods,
  1.1817 +                                              objArrayHandle methods_annotations,
  1.1818 +                                              objArrayHandle methods_parameter_annotations,
  1.1819 +                                              objArrayHandle methods_default_annotations,
  1.1820 +                                              TRAPS) {
  1.1821 +  typeArrayHandle nullHandle;
  1.1822 +  int length = methods()->length();
  1.1823 +  // If JVMTI original method ordering is enabled we have to
  1.1824 +  // remember the original class file ordering.
  1.1825 +  // We temporarily use the vtable_index field in the methodOop to store the
  1.1826 +  // class file index, so we can read in after calling qsort.
  1.1827 +  if (JvmtiExport::can_maintain_original_method_order()) {
  1.1828 +    for (int index = 0; index < length; index++) {
  1.1829 +      methodOop m = methodOop(methods->obj_at(index));
  1.1830 +      assert(!m->valid_vtable_index(), "vtable index should not be set");
  1.1831 +      m->set_vtable_index(index);
  1.1832 +    }
  1.1833 +  }
  1.1834 +  // Sort method array by ascending method name (for faster lookups & vtable construction)
  1.1835 +  // Note that the ordering is not alphabetical, see symbolOopDesc::fast_compare
  1.1836 +  methodOopDesc::sort_methods(methods(),
  1.1837 +                              methods_annotations(),
  1.1838 +                              methods_parameter_annotations(),
  1.1839 +                              methods_default_annotations());
  1.1840 +
  1.1841 +  // If JVMTI original method ordering is enabled construct int array remembering the original ordering
  1.1842 +  if (JvmtiExport::can_maintain_original_method_order()) {
  1.1843 +    typeArrayOop new_ordering = oopFactory::new_permanent_intArray(length, CHECK_(nullHandle));
  1.1844 +    typeArrayHandle method_ordering(THREAD, new_ordering);
  1.1845 +    for (int index = 0; index < length; index++) {
  1.1846 +      methodOop m = methodOop(methods->obj_at(index));
  1.1847 +      int old_index = m->vtable_index();
  1.1848 +      assert(old_index >= 0 && old_index < length, "invalid method index");
  1.1849 +      method_ordering->int_at_put(index, old_index);
  1.1850 +      m->set_vtable_index(methodOopDesc::invalid_vtable_index);
  1.1851 +    }
  1.1852 +    return method_ordering;
  1.1853 +  } else {
  1.1854 +    return typeArrayHandle(THREAD, Universe::the_empty_int_array());
  1.1855 +  }
  1.1856 +}
  1.1857 +
  1.1858 +
  1.1859 +void ClassFileParser::parse_classfile_sourcefile_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS) {
  1.1860 +  ClassFileStream* cfs = stream();
  1.1861 +  cfs->guarantee_more(2, CHECK);  // sourcefile_index
  1.1862 +  u2 sourcefile_index = cfs->get_u2_fast();
  1.1863 +  check_property(
  1.1864 +    valid_cp_range(sourcefile_index, cp->length()) &&
  1.1865 +      cp->tag_at(sourcefile_index).is_utf8(),
  1.1866 +    "Invalid SourceFile attribute at constant pool index %u in class file %s",
  1.1867 +    sourcefile_index, CHECK);
  1.1868 +  k->set_source_file_name(cp->symbol_at(sourcefile_index));
  1.1869 +}
  1.1870 +
  1.1871 +
  1.1872 +
  1.1873 +void ClassFileParser::parse_classfile_source_debug_extension_attribute(constantPoolHandle cp,
  1.1874 +                                                                       instanceKlassHandle k,
  1.1875 +                                                                       int length, TRAPS) {
  1.1876 +  ClassFileStream* cfs = stream();
  1.1877 +  u1* sde_buffer = cfs->get_u1_buffer();
  1.1878 +  assert(sde_buffer != NULL, "null sde buffer");
  1.1879 +
  1.1880 +  // Don't bother storing it if there is no way to retrieve it
  1.1881 +  if (JvmtiExport::can_get_source_debug_extension()) {
  1.1882 +    // Optimistically assume that only 1 byte UTF format is used
  1.1883 +    // (common case)
  1.1884 +    symbolOop sde_symbol = oopFactory::new_symbol((char*)sde_buffer,
  1.1885 +                                                  length, CHECK);
  1.1886 +    k->set_source_debug_extension(sde_symbol);
  1.1887 +  }
  1.1888 +  // Got utf8 string, set stream position forward
  1.1889 +  cfs->skip_u1(length, CHECK);
  1.1890 +}
  1.1891 +
  1.1892 +
  1.1893 +// Inner classes can be static, private or protected (classic VM does this)
  1.1894 +#define RECOGNIZED_INNER_CLASS_MODIFIERS (JVM_RECOGNIZED_CLASS_MODIFIERS | JVM_ACC_PRIVATE | JVM_ACC_PROTECTED | JVM_ACC_STATIC)
  1.1895 +
  1.1896 +// Return number of classes in the inner classes attribute table
  1.1897 +u2 ClassFileParser::parse_classfile_inner_classes_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS) {
  1.1898 +  ClassFileStream* cfs = stream();
  1.1899 +  cfs->guarantee_more(2, CHECK_0);  // length
  1.1900 +  u2 length = cfs->get_u2_fast();
  1.1901 +
  1.1902 +  // 4-tuples of shorts [inner_class_info_index, outer_class_info_index, inner_name_index, inner_class_access_flags]
  1.1903 +  typeArrayOop ic = oopFactory::new_permanent_shortArray(length*4, CHECK_0);
  1.1904 +  typeArrayHandle inner_classes(THREAD, ic);
  1.1905 +  int index = 0;
  1.1906 +  int cp_size = cp->length();
  1.1907 +  cfs->guarantee_more(8 * length, CHECK_0);  // 4-tuples of u2
  1.1908 +  for (int n = 0; n < length; n++) {
  1.1909 +    // Inner class index
  1.1910 +    u2 inner_class_info_index = cfs->get_u2_fast();
  1.1911 +    check_property(
  1.1912 +      inner_class_info_index == 0 ||
  1.1913 +        (valid_cp_range(inner_class_info_index, cp_size) &&
  1.1914 +        cp->tag_at(inner_class_info_index).is_klass_reference()),
  1.1915 +      "inner_class_info_index %u has bad constant type in class file %s",
  1.1916 +      inner_class_info_index, CHECK_0);
  1.1917 +    // Outer class index
  1.1918 +    u2 outer_class_info_index = cfs->get_u2_fast();
  1.1919 +    check_property(
  1.1920 +      outer_class_info_index == 0 ||
  1.1921 +        (valid_cp_range(outer_class_info_index, cp_size) &&
  1.1922 +        cp->tag_at(outer_class_info_index).is_klass_reference()),
  1.1923 +      "outer_class_info_index %u has bad constant type in class file %s",
  1.1924 +      outer_class_info_index, CHECK_0);
  1.1925 +    // Inner class name
  1.1926 +    u2 inner_name_index = cfs->get_u2_fast();
  1.1927 +    check_property(
  1.1928 +      inner_name_index == 0 || (valid_cp_range(inner_name_index, cp_size) &&
  1.1929 +        cp->tag_at(inner_name_index).is_utf8()),
  1.1930 +      "inner_name_index %u has bad constant type in class file %s",
  1.1931 +      inner_name_index, CHECK_0);
  1.1932 +    if (_need_verify) {
  1.1933 +      guarantee_property(inner_class_info_index != outer_class_info_index,
  1.1934 +                         "Class is both outer and inner class in class file %s", CHECK_0);
  1.1935 +    }
  1.1936 +    // Access flags
  1.1937 +    AccessFlags inner_access_flags;
  1.1938 +    jint flags = cfs->get_u2_fast() & RECOGNIZED_INNER_CLASS_MODIFIERS;
  1.1939 +    if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
  1.1940 +      // Set abstract bit for old class files for backward compatibility
  1.1941 +      flags |= JVM_ACC_ABSTRACT;
  1.1942 +    }
  1.1943 +    verify_legal_class_modifiers(flags, CHECK_0);
  1.1944 +    inner_access_flags.set_flags(flags);
  1.1945 +
  1.1946 +    inner_classes->short_at_put(index++, inner_class_info_index);
  1.1947 +    inner_classes->short_at_put(index++, outer_class_info_index);
  1.1948 +    inner_classes->short_at_put(index++, inner_name_index);
  1.1949 +    inner_classes->short_at_put(index++, inner_access_flags.as_short());
  1.1950 +  }
  1.1951 +
  1.1952 +  // 4347400: make sure there's no duplicate entry in the classes array
  1.1953 +  if (_need_verify && _major_version >= JAVA_1_5_VERSION) {
  1.1954 +    for(int i = 0; i < inner_classes->length(); i += 4) {
  1.1955 +      for(int j = i + 4; j < inner_classes->length(); j += 4) {
  1.1956 +        guarantee_property((inner_classes->ushort_at(i)   != inner_classes->ushort_at(j) ||
  1.1957 +                            inner_classes->ushort_at(i+1) != inner_classes->ushort_at(j+1) ||
  1.1958 +                            inner_classes->ushort_at(i+2) != inner_classes->ushort_at(j+2) ||
  1.1959 +                            inner_classes->ushort_at(i+3) != inner_classes->ushort_at(j+3)),
  1.1960 +                            "Duplicate entry in InnerClasses in class file %s",
  1.1961 +                            CHECK_0);
  1.1962 +      }
  1.1963 +    }
  1.1964 +  }
  1.1965 +
  1.1966 +  // Update instanceKlass with inner class info.
  1.1967 +  k->set_inner_classes(inner_classes());
  1.1968 +  return length;
  1.1969 +}
  1.1970 +
  1.1971 +void ClassFileParser::parse_classfile_synthetic_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS) {
  1.1972 +  k->set_is_synthetic();
  1.1973 +}
  1.1974 +
  1.1975 +void ClassFileParser::parse_classfile_signature_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS) {
  1.1976 +  ClassFileStream* cfs = stream();
  1.1977 +  u2 signature_index = cfs->get_u2(CHECK);
  1.1978 +  check_property(
  1.1979 +    valid_cp_range(signature_index, cp->length()) &&
  1.1980 +      cp->tag_at(signature_index).is_utf8(),
  1.1981 +    "Invalid constant pool index %u in Signature attribute in class file %s",
  1.1982 +    signature_index, CHECK);
  1.1983 +  k->set_generic_signature(cp->symbol_at(signature_index));
  1.1984 +}
  1.1985 +
  1.1986 +void ClassFileParser::parse_classfile_attributes(constantPoolHandle cp, instanceKlassHandle k, TRAPS) {
  1.1987 +  ClassFileStream* cfs = stream();
  1.1988 +  // Set inner classes attribute to default sentinel
  1.1989 +  k->set_inner_classes(Universe::the_empty_short_array());
  1.1990 +  cfs->guarantee_more(2, CHECK);  // attributes_count
  1.1991 +  u2 attributes_count = cfs->get_u2_fast();
  1.1992 +  bool parsed_sourcefile_attribute = false;
  1.1993 +  bool parsed_innerclasses_attribute = false;
  1.1994 +  bool parsed_enclosingmethod_attribute = false;
  1.1995 +  u1* runtime_visible_annotations = NULL;
  1.1996 +  int runtime_visible_annotations_length = 0;
  1.1997 +  u1* runtime_invisible_annotations = NULL;
  1.1998 +  int runtime_invisible_annotations_length = 0;
  1.1999 +  // Iterate over attributes
  1.2000 +  while (attributes_count--) {
  1.2001 +    cfs->guarantee_more(6, CHECK);  // attribute_name_index, attribute_length
  1.2002 +    u2 attribute_name_index = cfs->get_u2_fast();
  1.2003 +    u4 attribute_length = cfs->get_u4_fast();
  1.2004 +    check_property(
  1.2005 +      valid_cp_range(attribute_name_index, cp->length()) &&
  1.2006 +        cp->tag_at(attribute_name_index).is_utf8(),
  1.2007 +      "Attribute name has bad constant pool index %u in class file %s",
  1.2008 +      attribute_name_index, CHECK);
  1.2009 +    symbolOop tag = cp->symbol_at(attribute_name_index);
  1.2010 +    if (tag == vmSymbols::tag_source_file()) {
  1.2011 +      // Check for SourceFile tag
  1.2012 +      if (_need_verify) {
  1.2013 +        guarantee_property(attribute_length == 2, "Wrong SourceFile attribute length in class file %s", CHECK);
  1.2014 +      }
  1.2015 +      if (parsed_sourcefile_attribute) {
  1.2016 +        classfile_parse_error("Multiple SourceFile attributes in class file %s", CHECK);
  1.2017 +      } else {
  1.2018 +        parsed_sourcefile_attribute = true;
  1.2019 +      }
  1.2020 +      parse_classfile_sourcefile_attribute(cp, k, CHECK);
  1.2021 +    } else if (tag == vmSymbols::tag_source_debug_extension()) {
  1.2022 +      // Check for SourceDebugExtension tag
  1.2023 +      parse_classfile_source_debug_extension_attribute(cp, k, (int)attribute_length, CHECK);
  1.2024 +    } else if (tag == vmSymbols::tag_inner_classes()) {
  1.2025 +      // Check for InnerClasses tag
  1.2026 +      if (parsed_innerclasses_attribute) {
  1.2027 +        classfile_parse_error("Multiple InnerClasses attributes in class file %s", CHECK);
  1.2028 +      } else {
  1.2029 +        parsed_innerclasses_attribute = true;
  1.2030 +      }
  1.2031 +      u2 num_of_classes = parse_classfile_inner_classes_attribute(cp, k, CHECK);
  1.2032 +      if (_need_verify && _major_version >= JAVA_1_5_VERSION) {
  1.2033 +        guarantee_property(attribute_length == sizeof(num_of_classes) + 4 * sizeof(u2) * num_of_classes,
  1.2034 +                          "Wrong InnerClasses attribute length in class file %s", CHECK);
  1.2035 +      }
  1.2036 +    } else if (tag == vmSymbols::tag_synthetic()) {
  1.2037 +      // Check for Synthetic tag
  1.2038 +      // Shouldn't we check that the synthetic flags wasn't already set? - not required in spec
  1.2039 +      if (attribute_length != 0) {
  1.2040 +        classfile_parse_error(
  1.2041 +          "Invalid Synthetic classfile attribute length %u in class file %s",
  1.2042 +          attribute_length, CHECK);
  1.2043 +      }
  1.2044 +      parse_classfile_synthetic_attribute(cp, k, CHECK);
  1.2045 +    } else if (tag == vmSymbols::tag_deprecated()) {
  1.2046 +      // Check for Deprecatd tag - 4276120
  1.2047 +      if (attribute_length != 0) {
  1.2048 +        classfile_parse_error(
  1.2049 +          "Invalid Deprecated classfile attribute length %u in class file %s",
  1.2050 +          attribute_length, CHECK);
  1.2051 +      }
  1.2052 +    } else if (_major_version >= JAVA_1_5_VERSION) {
  1.2053 +      if (tag == vmSymbols::tag_signature()) {
  1.2054 +        if (attribute_length != 2) {
  1.2055 +          classfile_parse_error(
  1.2056 +            "Wrong Signature attribute length %u in class file %s",
  1.2057 +            attribute_length, CHECK);
  1.2058 +        }
  1.2059 +        parse_classfile_signature_attribute(cp, k, CHECK);
  1.2060 +      } else if (tag == vmSymbols::tag_runtime_visible_annotations()) {
  1.2061 +        runtime_visible_annotations_length = attribute_length;
  1.2062 +        runtime_visible_annotations = cfs->get_u1_buffer();
  1.2063 +        assert(runtime_visible_annotations != NULL, "null visible annotations");
  1.2064 +        cfs->skip_u1(runtime_visible_annotations_length, CHECK);
  1.2065 +      } else if (PreserveAllAnnotations && tag == vmSymbols::tag_runtime_invisible_annotations()) {
  1.2066 +        runtime_invisible_annotations_length = attribute_length;
  1.2067 +        runtime_invisible_annotations = cfs->get_u1_buffer();
  1.2068 +        assert(runtime_invisible_annotations != NULL, "null invisible annotations");
  1.2069 +        cfs->skip_u1(runtime_invisible_annotations_length, CHECK);
  1.2070 +      } else if (tag == vmSymbols::tag_enclosing_method()) {
  1.2071 +        if (parsed_enclosingmethod_attribute) {
  1.2072 +          classfile_parse_error("Multiple EnclosingMethod attributes in class file %s", CHECK);
  1.2073 +        }   else {
  1.2074 +          parsed_enclosingmethod_attribute = true;
  1.2075 +        }
  1.2076 +        cfs->guarantee_more(4, CHECK);  // class_index, method_index
  1.2077 +        u2 class_index  = cfs->get_u2_fast();
  1.2078 +        u2 method_index = cfs->get_u2_fast();
  1.2079 +        if (class_index == 0) {
  1.2080 +          classfile_parse_error("Invalid class index in EnclosingMethod attribute in class file %s", CHECK);
  1.2081 +        }
  1.2082 +        // Validate the constant pool indices and types
  1.2083 +        if (!cp->is_within_bounds(class_index) ||
  1.2084 +            !cp->tag_at(class_index).is_klass_reference()) {
  1.2085 +          classfile_parse_error("Invalid or out-of-bounds class index in EnclosingMethod attribute in class file %s", CHECK);
  1.2086 +        }
  1.2087 +        if (method_index != 0 &&
  1.2088 +            (!cp->is_within_bounds(method_index) ||
  1.2089 +             !cp->tag_at(method_index).is_name_and_type())) {
  1.2090 +          classfile_parse_error("Invalid or out-of-bounds method index in EnclosingMethod attribute in class file %s", CHECK);
  1.2091 +        }
  1.2092 +        k->set_enclosing_method_indices(class_index, method_index);
  1.2093 +      } else {
  1.2094 +        // Unknown attribute
  1.2095 +        cfs->skip_u1(attribute_length, CHECK);
  1.2096 +      }
  1.2097 +    } else {
  1.2098 +      // Unknown attribute
  1.2099 +      cfs->skip_u1(attribute_length, CHECK);
  1.2100 +    }
  1.2101 +  }
  1.2102 +  typeArrayHandle annotations = assemble_annotations(runtime_visible_annotations,
  1.2103 +                                                     runtime_visible_annotations_length,
  1.2104 +                                                     runtime_invisible_annotations,
  1.2105 +                                                     runtime_invisible_annotations_length,
  1.2106 +                                                     CHECK);
  1.2107 +  k->set_class_annotations(annotations());
  1.2108 +}
  1.2109 +
  1.2110 +
  1.2111 +typeArrayHandle ClassFileParser::assemble_annotations(u1* runtime_visible_annotations,
  1.2112 +                                                      int runtime_visible_annotations_length,
  1.2113 +                                                      u1* runtime_invisible_annotations,
  1.2114 +                                                      int runtime_invisible_annotations_length, TRAPS) {
  1.2115 +  typeArrayHandle annotations;
  1.2116 +  if (runtime_visible_annotations != NULL ||
  1.2117 +      runtime_invisible_annotations != NULL) {
  1.2118 +    typeArrayOop anno = oopFactory::new_permanent_byteArray(runtime_visible_annotations_length +
  1.2119 +                                                            runtime_invisible_annotations_length, CHECK_(annotations));
  1.2120 +    annotations = typeArrayHandle(THREAD, anno);
  1.2121 +    if (runtime_visible_annotations != NULL) {
  1.2122 +      memcpy(annotations->byte_at_addr(0), runtime_visible_annotations, runtime_visible_annotations_length);
  1.2123 +    }
  1.2124 +    if (runtime_invisible_annotations != NULL) {
  1.2125 +      memcpy(annotations->byte_at_addr(runtime_visible_annotations_length), runtime_invisible_annotations, runtime_invisible_annotations_length);
  1.2126 +    }
  1.2127 +  }
  1.2128 +  return annotations;
  1.2129 +}
  1.2130 +
  1.2131 +
  1.2132 +static void initialize_static_field(fieldDescriptor* fd, TRAPS) {
  1.2133 +  KlassHandle h_k (THREAD, fd->field_holder());
  1.2134 +  assert(h_k.not_null() && fd->is_static(), "just checking");
  1.2135 +  if (fd->has_initial_value()) {
  1.2136 +    BasicType t = fd->field_type();
  1.2137 +    switch (t) {
  1.2138 +      case T_BYTE:
  1.2139 +        h_k()->byte_field_put(fd->offset(), fd->int_initial_value());
  1.2140 +              break;
  1.2141 +      case T_BOOLEAN:
  1.2142 +        h_k()->bool_field_put(fd->offset(), fd->int_initial_value());
  1.2143 +              break;
  1.2144 +      case T_CHAR:
  1.2145 +        h_k()->char_field_put(fd->offset(), fd->int_initial_value());
  1.2146 +              break;
  1.2147 +      case T_SHORT:
  1.2148 +        h_k()->short_field_put(fd->offset(), fd->int_initial_value());
  1.2149 +              break;
  1.2150 +      case T_INT:
  1.2151 +        h_k()->int_field_put(fd->offset(), fd->int_initial_value());
  1.2152 +        break;
  1.2153 +      case T_FLOAT:
  1.2154 +        h_k()->float_field_put(fd->offset(), fd->float_initial_value());
  1.2155 +        break;
  1.2156 +      case T_DOUBLE:
  1.2157 +        h_k()->double_field_put(fd->offset(), fd->double_initial_value());
  1.2158 +        break;
  1.2159 +      case T_LONG:
  1.2160 +        h_k()->long_field_put(fd->offset(), fd->long_initial_value());
  1.2161 +        break;
  1.2162 +      case T_OBJECT:
  1.2163 +        {
  1.2164 +          #ifdef ASSERT
  1.2165 +          symbolOop sym = oopFactory::new_symbol("Ljava/lang/String;", CHECK);
  1.2166 +          assert(fd->signature() == sym, "just checking");
  1.2167 +          #endif
  1.2168 +          oop string = fd->string_initial_value(CHECK);
  1.2169 +          h_k()->obj_field_put(fd->offset(), string);
  1.2170 +        }
  1.2171 +        break;
  1.2172 +      default:
  1.2173 +        THROW_MSG(vmSymbols::java_lang_ClassFormatError(),
  1.2174 +                  "Illegal ConstantValue attribute in class file");
  1.2175 +    }
  1.2176 +  }
  1.2177 +}
  1.2178 +
  1.2179 +
  1.2180 +void ClassFileParser::java_lang_ref_Reference_fix_pre(typeArrayHandle* fields_ptr,
  1.2181 +  constantPoolHandle cp, FieldAllocationCount *fac_ptr, TRAPS) {
  1.2182 +  // This code is for compatibility with earlier jdk's that do not
  1.2183 +  // have the "discovered" field in java.lang.ref.Reference.  For 1.5
  1.2184 +  // the check for the "discovered" field should issue a warning if
  1.2185 +  // the field is not found.  For 1.6 this code should be issue a
  1.2186 +  // fatal error if the "discovered" field is not found.
  1.2187 +  //
  1.2188 +  // Increment fac.nonstatic_oop_count so that the start of the
  1.2189 +  // next type of non-static oops leaves room for the fake oop.
  1.2190 +  // Do not increment next_nonstatic_oop_offset so that the
  1.2191 +  // fake oop is place after the java.lang.ref.Reference oop
  1.2192 +  // fields.
  1.2193 +  //
  1.2194 +  // Check the fields in java.lang.ref.Reference for the "discovered"
  1.2195 +  // field.  If it is not present, artifically create a field for it.
  1.2196 +  // This allows this VM to run on early JDK where the field is not
  1.2197 +  // present.
  1.2198 +
  1.2199 +  //
  1.2200 +  // Increment fac.nonstatic_oop_count so that the start of the
  1.2201 +  // next type of non-static oops leaves room for the fake oop.
  1.2202 +  // Do not increment next_nonstatic_oop_offset so that the
  1.2203 +  // fake oop is place after the java.lang.ref.Reference oop
  1.2204 +  // fields.
  1.2205 +  //
  1.2206 +  // Check the fields in java.lang.ref.Reference for the "discovered"
  1.2207 +  // field.  If it is not present, artifically create a field for it.
  1.2208 +  // This allows this VM to run on early JDK where the field is not
  1.2209 +  // present.
  1.2210 +  int reference_sig_index = 0;
  1.2211 +  int reference_name_index = 0;
  1.2212 +  int reference_index = 0;
  1.2213 +  int extra = java_lang_ref_Reference::number_of_fake_oop_fields;
  1.2214 +  const int n = (*fields_ptr)()->length();
  1.2215 +  for (int i = 0; i < n; i += instanceKlass::next_offset ) {
  1.2216 +    int name_index =
  1.2217 +    (*fields_ptr)()->ushort_at(i + instanceKlass::name_index_offset);
  1.2218 +    int sig_index  =
  1.2219 +      (*fields_ptr)()->ushort_at(i + instanceKlass::signature_index_offset);
  1.2220 +    symbolOop f_name = cp->symbol_at(name_index);
  1.2221 +    symbolOop f_sig  = cp->symbol_at(sig_index);
  1.2222 +    if (f_sig == vmSymbols::reference_signature() && reference_index == 0) {
  1.2223 +      // Save the index for reference signature for later use.
  1.2224 +      // The fake discovered field does not entries in the
  1.2225 +      // constant pool so the index for its signature cannot
  1.2226 +      // be extracted from the constant pool.  It will need
  1.2227 +      // later, however.  It's signature is vmSymbols::reference_signature()
  1.2228 +      // so same an index for that signature.
  1.2229 +      reference_sig_index = sig_index;
  1.2230 +      reference_name_index = name_index;
  1.2231 +      reference_index = i;
  1.2232 +    }
  1.2233 +    if (f_name == vmSymbols::reference_discovered_name() &&
  1.2234 +      f_sig == vmSymbols::reference_signature()) {
  1.2235 +      // The values below are fake but will force extra
  1.2236 +      // non-static oop fields and a corresponding non-static
  1.2237 +      // oop map block to be allocated.
  1.2238 +      extra = 0;
  1.2239 +      break;
  1.2240 +    }
  1.2241 +  }
  1.2242 +  if (extra != 0) {
  1.2243 +    fac_ptr->nonstatic_oop_count += extra;
  1.2244 +    // Add the additional entry to "fields" so that the klass
  1.2245 +    // contains the "discoverd" field and the field will be initialized
  1.2246 +    // in instances of the object.
  1.2247 +    int fields_with_fix_length = (*fields_ptr)()->length() +
  1.2248 +      instanceKlass::next_offset;
  1.2249 +    typeArrayOop ff = oopFactory::new_permanent_shortArray(
  1.2250 +                                                fields_with_fix_length, CHECK);
  1.2251 +    typeArrayHandle fields_with_fix(THREAD, ff);
  1.2252 +
  1.2253 +    // Take everything from the original but the length.
  1.2254 +    for (int idx = 0; idx < (*fields_ptr)->length(); idx++) {
  1.2255 +      fields_with_fix->ushort_at_put(idx, (*fields_ptr)->ushort_at(idx));
  1.2256 +    }
  1.2257 +
  1.2258 +    // Add the fake field at the end.
  1.2259 +    int i = (*fields_ptr)->length();
  1.2260 +    // There is no name index for the fake "discovered" field nor
  1.2261 +    // signature but a signature is needed so that the field will
  1.2262 +    // be properly initialized.  Use one found for
  1.2263 +    // one of the other reference fields. Be sure the index for the
  1.2264 +    // name is 0.  In fieldDescriptor::initialize() the index of the
  1.2265 +    // name is checked.  That check is by passed for the last nonstatic
  1.2266 +    // oop field in a java.lang.ref.Reference which is assumed to be
  1.2267 +    // this artificial "discovered" field.  An assertion checks that
  1.2268 +    // the name index is 0.
  1.2269 +    assert(reference_index != 0, "Missing signature for reference");
  1.2270 +
  1.2271 +    int j;
  1.2272 +    for (j = 0; j < instanceKlass::next_offset; j++) {
  1.2273 +      fields_with_fix->ushort_at_put(i + j,
  1.2274 +        (*fields_ptr)->ushort_at(reference_index +j));
  1.2275 +    }
  1.2276 +    // Clear the public access flag and set the private access flag.
  1.2277 +    short flags;
  1.2278 +    flags =
  1.2279 +      fields_with_fix->ushort_at(i + instanceKlass::access_flags_offset);
  1.2280 +    assert(!(flags & JVM_RECOGNIZED_FIELD_MODIFIERS), "Unexpected access flags set");
  1.2281 +    flags = flags & (~JVM_ACC_PUBLIC);
  1.2282 +    flags = flags | JVM_ACC_PRIVATE;
  1.2283 +    AccessFlags access_flags;
  1.2284 +    access_flags.set_flags(flags);
  1.2285 +    assert(!access_flags.is_public(), "Failed to clear public flag");
  1.2286 +    assert(access_flags.is_private(), "Failed to set private flag");
  1.2287 +    fields_with_fix->ushort_at_put(i + instanceKlass::access_flags_offset,
  1.2288 +      flags);
  1.2289 +
  1.2290 +    assert(fields_with_fix->ushort_at(i + instanceKlass::name_index_offset)
  1.2291 +      == reference_name_index, "The fake reference name is incorrect");
  1.2292 +    assert(fields_with_fix->ushort_at(i + instanceKlass::signature_index_offset)
  1.2293 +      == reference_sig_index, "The fake reference signature is incorrect");
  1.2294 +    // The type of the field is stored in the low_offset entry during
  1.2295 +    // parsing.
  1.2296 +    assert(fields_with_fix->ushort_at(i + instanceKlass::low_offset) ==
  1.2297 +      NONSTATIC_OOP, "The fake reference type is incorrect");
  1.2298 +
  1.2299 +    // "fields" is allocated in the permanent generation.  Disgard
  1.2300 +    // it and let it be collected.
  1.2301 +    (*fields_ptr) = fields_with_fix;
  1.2302 +  }
  1.2303 +  return;
  1.2304 +}
  1.2305 +
  1.2306 +
  1.2307 +void ClassFileParser::java_lang_Class_fix_pre(objArrayHandle* methods_ptr,
  1.2308 +  FieldAllocationCount *fac_ptr, TRAPS) {
  1.2309 +  // Add fake fields for java.lang.Class instances
  1.2310 +  //
  1.2311 +  // This is not particularly nice. We should consider adding a
  1.2312 +  // private transient object field at the Java level to
  1.2313 +  // java.lang.Class. Alternatively we could add a subclass of
  1.2314 +  // instanceKlass which provides an accessor and size computer for
  1.2315 +  // this field, but that appears to be more code than this hack.
  1.2316 +  //
  1.2317 +  // NOTE that we wedge these in at the beginning rather than the
  1.2318 +  // end of the object because the Class layout changed between JDK
  1.2319 +  // 1.3 and JDK 1.4 with the new reflection implementation; some
  1.2320 +  // nonstatic oop fields were added at the Java level. The offsets
  1.2321 +  // of these fake fields can't change between these two JDK
  1.2322 +  // versions because when the offsets are computed at bootstrap
  1.2323 +  // time we don't know yet which version of the JDK we're running in.
  1.2324 +
  1.2325 +  // The values below are fake but will force two non-static oop fields and
  1.2326 +  // a corresponding non-static oop map block to be allocated.
  1.2327 +  const int extra = java_lang_Class::number_of_fake_oop_fields;
  1.2328 +  fac_ptr->nonstatic_oop_count += extra;
  1.2329 +}
  1.2330 +
  1.2331 +
  1.2332 +void ClassFileParser::java_lang_Class_fix_post(int* next_nonstatic_oop_offset_ptr) {
  1.2333 +  // Cause the extra fake fields in java.lang.Class to show up before
  1.2334 +  // the Java fields for layout compatibility between 1.3 and 1.4
  1.2335 +  // Incrementing next_nonstatic_oop_offset here advances the
  1.2336 +  // location where the real java fields are placed.
  1.2337 +  const int extra = java_lang_Class::number_of_fake_oop_fields;
  1.2338 +  (*next_nonstatic_oop_offset_ptr) += (extra * wordSize);
  1.2339 +}
  1.2340 +
  1.2341 +
  1.2342 +instanceKlassHandle ClassFileParser::parseClassFile(symbolHandle name,
  1.2343 +                                                    Handle class_loader,
  1.2344 +                                                    Handle protection_domain,
  1.2345 +                                                    symbolHandle& parsed_name,
  1.2346 +                                                    TRAPS) {
  1.2347 +  // So that JVMTI can cache class file in the state before retransformable agents
  1.2348 +  // have modified it
  1.2349 +  unsigned char *cached_class_file_bytes = NULL;
  1.2350 +  jint cached_class_file_length;
  1.2351 +
  1.2352 +  ClassFileStream* cfs = stream();
  1.2353 +  // Timing
  1.2354 +  PerfTraceTime vmtimer(ClassLoader::perf_accumulated_time());
  1.2355 +
  1.2356 +  _has_finalizer = _has_empty_finalizer = _has_vanilla_constructor = false;
  1.2357 +
  1.2358 +  if (JvmtiExport::should_post_class_file_load_hook()) {
  1.2359 +    unsigned char* ptr = cfs->buffer();
  1.2360 +    unsigned char* end_ptr = cfs->buffer() + cfs->length();
  1.2361 +
  1.2362 +    JvmtiExport::post_class_file_load_hook(name, class_loader, protection_domain,
  1.2363 +                                           &ptr, &end_ptr,
  1.2364 +                                           &cached_class_file_bytes,
  1.2365 +                                           &cached_class_file_length);
  1.2366 +
  1.2367 +    if (ptr != cfs->buffer()) {
  1.2368 +      // JVMTI agent has modified class file data.
  1.2369 +      // Set new class file stream using JVMTI agent modified
  1.2370 +      // class file data.
  1.2371 +      cfs = new ClassFileStream(ptr, end_ptr - ptr, cfs->source());
  1.2372 +      set_stream(cfs);
  1.2373 +    }
  1.2374 +  }
  1.2375 +
  1.2376 +
  1.2377 +  instanceKlassHandle nullHandle;
  1.2378 +
  1.2379 +  // Figure out whether we can skip format checking (matching classic VM behavior)
  1.2380 +  _need_verify = Verifier::should_verify_for(class_loader());
  1.2381 +
  1.2382 +  // Set the verify flag in stream
  1.2383 +  cfs->set_verify(_need_verify);
  1.2384 +
  1.2385 +  // Save the class file name for easier error message printing.
  1.2386 +  _class_name = name.not_null()? name : vmSymbolHandles::unknown_class_name();
  1.2387 +
  1.2388 +  cfs->guarantee_more(8, CHECK_(nullHandle));  // magic, major, minor
  1.2389 +  // Magic value
  1.2390 +  u4 magic = cfs->get_u4_fast();
  1.2391 +  guarantee_property(magic == JAVA_CLASSFILE_MAGIC,
  1.2392 +                     "Incompatible magic value %u in class file %s",
  1.2393 +                     magic, CHECK_(nullHandle));
  1.2394 +
  1.2395 +  // Version numbers
  1.2396 +  u2 minor_version = cfs->get_u2_fast();
  1.2397 +  u2 major_version = cfs->get_u2_fast();
  1.2398 +
  1.2399 +  // Check version numbers - we check this even with verifier off
  1.2400 +  if (!is_supported_version(major_version, minor_version)) {
  1.2401 +    if (name.is_null()) {
  1.2402 +      Exceptions::fthrow(
  1.2403 +        THREAD_AND_LOCATION,
  1.2404 +        vmSymbolHandles::java_lang_UnsupportedClassVersionError(),
  1.2405 +        "Unsupported major.minor version %u.%u",
  1.2406 +        major_version,
  1.2407 +        minor_version);
  1.2408 +    } else {
  1.2409 +      ResourceMark rm(THREAD);
  1.2410 +      Exceptions::fthrow(
  1.2411 +        THREAD_AND_LOCATION,
  1.2412 +        vmSymbolHandles::java_lang_UnsupportedClassVersionError(),
  1.2413 +        "%s : Unsupported major.minor version %u.%u",
  1.2414 +        name->as_C_string(),
  1.2415 +        major_version,
  1.2416 +        minor_version);
  1.2417 +    }
  1.2418 +    return nullHandle;
  1.2419 +  }
  1.2420 +
  1.2421 +  _major_version = major_version;
  1.2422 +  _minor_version = minor_version;
  1.2423 +
  1.2424 +
  1.2425 +  // Check if verification needs to be relaxed for this class file
  1.2426 +  // Do not restrict it to jdk1.0 or jdk1.1 to maintain backward compatibility (4982376)
  1.2427 +  _relax_verify = Verifier::relax_verify_for(class_loader());
  1.2428 +
  1.2429 +  // Constant pool
  1.2430 +  constantPoolHandle cp = parse_constant_pool(CHECK_(nullHandle));
  1.2431 +  int cp_size = cp->length();
  1.2432 +
  1.2433 +  cfs->guarantee_more(8, CHECK_(nullHandle));  // flags, this_class, super_class, infs_len
  1.2434 +
  1.2435 +  // Access flags
  1.2436 +  AccessFlags access_flags;
  1.2437 +  jint flags = cfs->get_u2_fast() & JVM_RECOGNIZED_CLASS_MODIFIERS;
  1.2438 +
  1.2439 +  if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
  1.2440 +    // Set abstract bit for old class files for backward compatibility
  1.2441 +    flags |= JVM_ACC_ABSTRACT;
  1.2442 +  }
  1.2443 +  verify_legal_class_modifiers(flags, CHECK_(nullHandle));
  1.2444 +  access_flags.set_flags(flags);
  1.2445 +
  1.2446 +  // This class and superclass
  1.2447 +  instanceKlassHandle super_klass;
  1.2448 +  u2 this_class_index = cfs->get_u2_fast();
  1.2449 +  check_property(
  1.2450 +    valid_cp_range(this_class_index, cp_size) &&
  1.2451 +      cp->tag_at(this_class_index).is_unresolved_klass(),
  1.2452 +    "Invalid this class index %u in constant pool in class file %s",
  1.2453 +    this_class_index, CHECK_(nullHandle));
  1.2454 +
  1.2455 +  symbolHandle class_name (THREAD, cp->unresolved_klass_at(this_class_index));
  1.2456 +  assert(class_name.not_null(), "class_name can't be null");
  1.2457 +
  1.2458 +  // It's important to set parsed_name *before* resolving the super class.
  1.2459 +  // (it's used for cleanup by the caller if parsing fails)
  1.2460 +  parsed_name = class_name;
  1.2461 +
  1.2462 +  // Update _class_name which could be null previously to be class_name
  1.2463 +  _class_name = class_name;
  1.2464 +
  1.2465 +  // Don't need to check whether this class name is legal or not.
  1.2466 +  // It has been checked when constant pool is parsed.
  1.2467 +  // However, make sure it is not an array type.
  1.2468 +  if (_need_verify) {
  1.2469 +    guarantee_property(class_name->byte_at(0) != JVM_SIGNATURE_ARRAY,
  1.2470 +                       "Bad class name in class file %s",
  1.2471 +                       CHECK_(nullHandle));
  1.2472 +  }
  1.2473 +
  1.2474 +  klassOop preserve_this_klass;   // for storing result across HandleMark
  1.2475 +
  1.2476 +  // release all handles when parsing is done
  1.2477 +  { HandleMark hm(THREAD);
  1.2478 +
  1.2479 +    // Checks if name in class file matches requested name
  1.2480 +    if (name.not_null() && class_name() != name()) {
  1.2481 +      ResourceMark rm(THREAD);
  1.2482 +      Exceptions::fthrow(
  1.2483 +        THREAD_AND_LOCATION,
  1.2484 +        vmSymbolHandles::java_lang_NoClassDefFoundError(),
  1.2485 +        "%s (wrong name: %s)",
  1.2486 +        name->as_C_string(),
  1.2487 +        class_name->as_C_string()
  1.2488 +      );
  1.2489 +      return nullHandle;
  1.2490 +    }
  1.2491 +
  1.2492 +    if (TraceClassLoadingPreorder) {
  1.2493 +      tty->print("[Loading %s", name()->as_klass_external_name());
  1.2494 +      if (cfs->source() != NULL) tty->print(" from %s", cfs->source());
  1.2495 +      tty->print_cr("]");
  1.2496 +    }
  1.2497 +
  1.2498 +    u2 super_class_index = cfs->get_u2_fast();
  1.2499 +    if (super_class_index == 0) {
  1.2500 +      check_property(class_name() == vmSymbols::java_lang_Object(),
  1.2501 +                     "Invalid superclass index %u in class file %s",
  1.2502 +                     super_class_index,
  1.2503 +                     CHECK_(nullHandle));
  1.2504 +    } else {
  1.2505 +      check_property(valid_cp_range(super_class_index, cp_size) &&
  1.2506 +                     cp->tag_at(super_class_index).is_unresolved_klass(),
  1.2507 +                     "Invalid superclass index %u in class file %s",
  1.2508 +                     super_class_index,
  1.2509 +                     CHECK_(nullHandle));
  1.2510 +      // The class name should be legal because it is checked when parsing constant pool.
  1.2511 +      // However, make sure it is not an array type.
  1.2512 +      if (_need_verify) {
  1.2513 +        guarantee_property(cp->unresolved_klass_at(super_class_index)->byte_at(0) != JVM_SIGNATURE_ARRAY,
  1.2514 +                          "Bad superclass name in class file %s", CHECK_(nullHandle));
  1.2515 +      }
  1.2516 +    }
  1.2517 +
  1.2518 +    // Interfaces
  1.2519 +    u2 itfs_len = cfs->get_u2_fast();
  1.2520 +    objArrayHandle local_interfaces;
  1.2521 +    if (itfs_len == 0) {
  1.2522 +      local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  1.2523 +    } else {
  1.2524 +      local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, &vmtimer, _class_name, CHECK_(nullHandle));
  1.2525 +    }
  1.2526 +
  1.2527 +    // Fields (offsets are filled in later)
  1.2528 +    struct FieldAllocationCount fac = {0,0,0,0,0,0,0,0,0,0};
  1.2529 +    objArrayHandle fields_annotations;
  1.2530 +    typeArrayHandle fields = parse_fields(cp, access_flags.is_interface(), &fac, &fields_annotations, CHECK_(nullHandle));
  1.2531 +    // Methods
  1.2532 +    bool has_final_method = false;
  1.2533 +    AccessFlags promoted_flags;
  1.2534 +    promoted_flags.set_flags(0);
  1.2535 +    // These need to be oop pointers because they are allocated lazily
  1.2536 +    // inside parse_methods inside a nested HandleMark
  1.2537 +    objArrayOop methods_annotations_oop = NULL;
  1.2538 +    objArrayOop methods_parameter_annotations_oop = NULL;
  1.2539 +    objArrayOop methods_default_annotations_oop = NULL;
  1.2540 +    objArrayHandle methods = parse_methods(cp, access_flags.is_interface(),
  1.2541 +                                           &promoted_flags,
  1.2542 +                                           &has_final_method,
  1.2543 +                                           &methods_annotations_oop,
  1.2544 +                                           &methods_parameter_annotations_oop,
  1.2545 +                                           &methods_default_annotations_oop,
  1.2546 +                                           CHECK_(nullHandle));
  1.2547 +
  1.2548 +    objArrayHandle methods_annotations(THREAD, methods_annotations_oop);
  1.2549 +    objArrayHandle methods_parameter_annotations(THREAD, methods_parameter_annotations_oop);
  1.2550 +    objArrayHandle methods_default_annotations(THREAD, methods_default_annotations_oop);
  1.2551 +
  1.2552 +    // We check super class after class file is parsed and format is checked
  1.2553 +    if (super_class_index > 0) {
  1.2554 +      symbolHandle sk (THREAD, cp->klass_name_at(super_class_index));
  1.2555 +      if (access_flags.is_interface()) {
  1.2556 +        // Before attempting to resolve the superclass, check for class format
  1.2557 +        // errors not checked yet.
  1.2558 +        guarantee_property(sk() == vmSymbols::java_lang_Object(),
  1.2559 +                           "Interfaces must have java.lang.Object as superclass in class file %s",
  1.2560 +                           CHECK_(nullHandle));
  1.2561 +      }
  1.2562 +      klassOop k = SystemDictionary::resolve_super_or_fail(class_name,
  1.2563 +                                                           sk,
  1.2564 +                                                           class_loader,
  1.2565 +                                                           protection_domain,
  1.2566 +                                                           true,
  1.2567 +                                                           CHECK_(nullHandle));
  1.2568 +      KlassHandle kh (THREAD, k);
  1.2569 +      super_klass = instanceKlassHandle(THREAD, kh());
  1.2570 +      if (super_klass->is_interface()) {
  1.2571 +        ResourceMark rm(THREAD);
  1.2572 +        Exceptions::fthrow(
  1.2573 +          THREAD_AND_LOCATION,
  1.2574 +          vmSymbolHandles::java_lang_IncompatibleClassChangeError(),
  1.2575 +          "class %s has interface %s as super class",
  1.2576 +          class_name->as_klass_external_name(),
  1.2577 +          super_klass->external_name()
  1.2578 +        );
  1.2579 +        return nullHandle;
  1.2580 +      }
  1.2581 +      // Make sure super class is not final
  1.2582 +      if (super_klass->is_final()) {
  1.2583 +        THROW_MSG_(vmSymbols::java_lang_VerifyError(), "Cannot inherit from final class", nullHandle);
  1.2584 +      }
  1.2585 +    }
  1.2586 +
  1.2587 +    // Compute the transitive list of all unique interfaces implemented by this class
  1.2588 +    objArrayHandle transitive_interfaces = compute_transitive_interfaces(super_klass, local_interfaces, CHECK_(nullHandle));
  1.2589 +
  1.2590 +    // sort methods
  1.2591 +    typeArrayHandle method_ordering = sort_methods(methods,
  1.2592 +                                                   methods_annotations,
  1.2593 +                                                   methods_parameter_annotations,
  1.2594 +                                                   methods_default_annotations,
  1.2595 +                                                   CHECK_(nullHandle));
  1.2596 +
  1.2597 +    // promote flags from parse_methods() to the klass' flags
  1.2598 +    access_flags.add_promoted_flags(promoted_flags.as_int());
  1.2599 +
  1.2600 +    // Size of Java vtable (in words)
  1.2601 +    int vtable_size = 0;
  1.2602 +    int itable_size = 0;
  1.2603 +    int num_miranda_methods = 0;
  1.2604 +
  1.2605 +    klassVtable::compute_vtable_size_and_num_mirandas(vtable_size,
  1.2606 +                                                      num_miranda_methods,
  1.2607 +                                                      super_klass(),
  1.2608 +                                                      methods(),
  1.2609 +                                                      access_flags,
  1.2610 +                                                      class_loader(),
  1.2611 +                                                      class_name(),
  1.2612 +                                                      local_interfaces());
  1.2613 +
  1.2614 +    // Size of Java itable (in words)
  1.2615 +    itable_size = access_flags.is_interface() ? 0 : klassItable::compute_itable_size(transitive_interfaces);
  1.2616 +
  1.2617 +    // Field size and offset computation
  1.2618 +    int nonstatic_field_size = super_klass() == NULL ? 0 : super_klass->nonstatic_field_size();
  1.2619 +#ifndef PRODUCT
  1.2620 +    int orig_nonstatic_field_size = 0;
  1.2621 +#endif
  1.2622 +    int static_field_size = 0;
  1.2623 +    int next_static_oop_offset;
  1.2624 +    int next_static_double_offset;
  1.2625 +    int next_static_word_offset;
  1.2626 +    int next_static_short_offset;
  1.2627 +    int next_static_byte_offset;
  1.2628 +    int next_static_type_offset;
  1.2629 +    int next_nonstatic_oop_offset;
  1.2630 +    int next_nonstatic_double_offset;
  1.2631 +    int next_nonstatic_word_offset;
  1.2632 +    int next_nonstatic_short_offset;
  1.2633 +    int next_nonstatic_byte_offset;
  1.2634 +    int next_nonstatic_type_offset;
  1.2635 +    int first_nonstatic_oop_offset;
  1.2636 +    int first_nonstatic_field_offset;
  1.2637 +    int next_nonstatic_field_offset;
  1.2638 +
  1.2639 +    // Calculate the starting byte offsets
  1.2640 +    next_static_oop_offset      = (instanceKlass::header_size() +
  1.2641 +                                  align_object_offset(vtable_size) +
  1.2642 +                                  align_object_offset(itable_size)) * wordSize;
  1.2643 +    next_static_double_offset   = next_static_oop_offset +
  1.2644 +                                  (fac.static_oop_count * oopSize);
  1.2645 +    if ( fac.static_double_count &&
  1.2646 +         (Universe::field_type_should_be_aligned(T_DOUBLE) ||
  1.2647 +          Universe::field_type_should_be_aligned(T_LONG)) ) {
  1.2648 +      next_static_double_offset = align_size_up(next_static_double_offset, BytesPerLong);
  1.2649 +    }
  1.2650 +
  1.2651 +    next_static_word_offset     = next_static_double_offset +
  1.2652 +                                  (fac.static_double_count * BytesPerLong);
  1.2653 +    next_static_short_offset    = next_static_word_offset +
  1.2654 +                                  (fac.static_word_count * BytesPerInt);
  1.2655 +    next_static_byte_offset     = next_static_short_offset +
  1.2656 +                                  (fac.static_short_count * BytesPerShort);
  1.2657 +    next_static_type_offset     = align_size_up((next_static_byte_offset +
  1.2658 +                                  fac.static_byte_count ), wordSize );
  1.2659 +    static_field_size           = (next_static_type_offset -
  1.2660 +                                  next_static_oop_offset) / wordSize;
  1.2661 +    first_nonstatic_field_offset = (instanceOopDesc::header_size() +
  1.2662 +                                    nonstatic_field_size) * wordSize;
  1.2663 +    next_nonstatic_field_offset = first_nonstatic_field_offset;
  1.2664 +
  1.2665 +    // Add fake fields for java.lang.Class instances (also see below)
  1.2666 +    if (class_name() == vmSymbols::java_lang_Class() && class_loader.is_null()) {
  1.2667 +      java_lang_Class_fix_pre(&methods, &fac, CHECK_(nullHandle));
  1.2668 +    }
  1.2669 +
  1.2670 +    // Add a fake "discovered" field if it is not present
  1.2671 +    // for compatibility with earlier jdk's.
  1.2672 +    if (class_name() == vmSymbols::java_lang_ref_Reference()
  1.2673 +      && class_loader.is_null()) {
  1.2674 +      java_lang_ref_Reference_fix_pre(&fields, cp, &fac, CHECK_(nullHandle));
  1.2675 +    }
  1.2676 +    // end of "discovered" field compactibility fix
  1.2677 +
  1.2678 +    int nonstatic_double_count = fac.nonstatic_double_count;
  1.2679 +    int nonstatic_word_count   = fac.nonstatic_word_count;
  1.2680 +    int nonstatic_short_count  = fac.nonstatic_short_count;
  1.2681 +    int nonstatic_byte_count   = fac.nonstatic_byte_count;
  1.2682 +    int nonstatic_oop_count    = fac.nonstatic_oop_count;
  1.2683 +
  1.2684 +    // Prepare list of oops for oop maps generation.
  1.2685 +    u2* nonstatic_oop_offsets;
  1.2686 +    u2* nonstatic_oop_length;
  1.2687 +    int nonstatic_oop_map_count = 0;
  1.2688 +
  1.2689 +    nonstatic_oop_offsets = NEW_RESOURCE_ARRAY_IN_THREAD(
  1.2690 +              THREAD, u2,  nonstatic_oop_count+1);
  1.2691 +    nonstatic_oop_length  = NEW_RESOURCE_ARRAY_IN_THREAD(
  1.2692 +              THREAD, u2,  nonstatic_oop_count+1);
  1.2693 +
  1.2694 +    // Add fake fields for java.lang.Class instances (also see above).
  1.2695 +    // FieldsAllocationStyle and CompactFields values will be reset to default.
  1.2696 +    if(class_name() == vmSymbols::java_lang_Class() && class_loader.is_null()) {
  1.2697 +      java_lang_Class_fix_post(&next_nonstatic_field_offset);
  1.2698 +      nonstatic_oop_offsets[0] = (u2)first_nonstatic_field_offset;
  1.2699 +      int fake_oop_count       = (( next_nonstatic_field_offset -
  1.2700 +                                    first_nonstatic_field_offset ) / oopSize);
  1.2701 +      nonstatic_oop_length [0] = (u2)fake_oop_count;
  1.2702 +      nonstatic_oop_map_count  = 1;
  1.2703 +      nonstatic_oop_count     -= fake_oop_count;
  1.2704 +      first_nonstatic_oop_offset = first_nonstatic_field_offset;
  1.2705 +    } else {
  1.2706 +      first_nonstatic_oop_offset = 0; // will be set for first oop field
  1.2707 +    }
  1.2708 +
  1.2709 +#ifndef PRODUCT
  1.2710 +    if( PrintCompactFieldsSavings ) {
  1.2711 +      next_nonstatic_double_offset = next_nonstatic_field_offset +
  1.2712 +                                     (nonstatic_oop_count * oopSize);
  1.2713 +      if ( nonstatic_double_count > 0 ) {
  1.2714 +        next_nonstatic_double_offset = align_size_up(next_nonstatic_double_offset, BytesPerLong);
  1.2715 +      }
  1.2716 +      next_nonstatic_word_offset  = next_nonstatic_double_offset +
  1.2717 +                                    (nonstatic_double_count * BytesPerLong);
  1.2718 +      next_nonstatic_short_offset = next_nonstatic_word_offset +
  1.2719 +                                    (nonstatic_word_count * BytesPerInt);
  1.2720 +      next_nonstatic_byte_offset  = next_nonstatic_short_offset +
  1.2721 +                                    (nonstatic_short_count * BytesPerShort);
  1.2722 +      next_nonstatic_type_offset  = align_size_up((next_nonstatic_byte_offset +
  1.2723 +                                    nonstatic_byte_count ), wordSize );
  1.2724 +      orig_nonstatic_field_size   = nonstatic_field_size +
  1.2725 +        ((next_nonstatic_type_offset - first_nonstatic_field_offset)/wordSize);
  1.2726 +    }
  1.2727 +#endif
  1.2728 +    bool compact_fields   = CompactFields;
  1.2729 +    int  allocation_style = FieldsAllocationStyle;
  1.2730 +    if( allocation_style < 0 || allocation_style > 1 ) { // Out of range?
  1.2731 +      assert(false, "0 <= FieldsAllocationStyle <= 1");
  1.2732 +      allocation_style = 1; // Optimistic
  1.2733 +    }
  1.2734 +
  1.2735 +    // The next classes have predefined hard-coded fields offsets
  1.2736 +    // (see in JavaClasses::compute_hard_coded_offsets()).
  1.2737 +    // Use default fields allocation order for them.
  1.2738 +    if( (allocation_style != 0 || compact_fields ) && class_loader.is_null() &&
  1.2739 +        (class_name() == vmSymbols::java_lang_AssertionStatusDirectives() ||
  1.2740 +         class_name() == vmSymbols::java_lang_Class() ||
  1.2741 +         class_name() == vmSymbols::java_lang_ClassLoader() ||
  1.2742 +         class_name() == vmSymbols::java_lang_ref_Reference() ||
  1.2743 +         class_name() == vmSymbols::java_lang_ref_SoftReference() ||
  1.2744 +         class_name() == vmSymbols::java_lang_StackTraceElement() ||
  1.2745 +         class_name() == vmSymbols::java_lang_String() ||
  1.2746 +         class_name() == vmSymbols::java_lang_Throwable()) ) {
  1.2747 +      allocation_style = 0;     // Allocate oops first
  1.2748 +      compact_fields   = false; // Don't compact fields
  1.2749 +    }
  1.2750 +
  1.2751 +    if( allocation_style == 0 ) {
  1.2752 +      // Fields order: oops, longs/doubles, ints, shorts/chars, bytes
  1.2753 +      next_nonstatic_oop_offset    = next_nonstatic_field_offset;
  1.2754 +      next_nonstatic_double_offset = next_nonstatic_oop_offset +
  1.2755 +                                     (nonstatic_oop_count * oopSize);
  1.2756 +    } else if( allocation_style == 1 ) {
  1.2757 +      // Fields order: longs/doubles, ints, shorts/chars, bytes, oops
  1.2758 +      next_nonstatic_double_offset = next_nonstatic_field_offset;
  1.2759 +    } else {
  1.2760 +      ShouldNotReachHere();
  1.2761 +    }
  1.2762 +
  1.2763 +    int nonstatic_oop_space_count   = 0;
  1.2764 +    int nonstatic_word_space_count  = 0;
  1.2765 +    int nonstatic_short_space_count = 0;
  1.2766 +    int nonstatic_byte_space_count  = 0;
  1.2767 +    int nonstatic_oop_space_offset;
  1.2768 +    int nonstatic_word_space_offset;
  1.2769 +    int nonstatic_short_space_offset;
  1.2770 +    int nonstatic_byte_space_offset;
  1.2771 +
  1.2772 +    if( nonstatic_double_count > 0 ) {
  1.2773 +      int offset = next_nonstatic_double_offset;
  1.2774 +      next_nonstatic_double_offset = align_size_up(offset, BytesPerLong);
  1.2775 +      if( compact_fields && offset != next_nonstatic_double_offset ) {
  1.2776 +        // Allocate available fields into the gap before double field.
  1.2777 +        int length = next_nonstatic_double_offset - offset;
  1.2778 +        assert(length == BytesPerInt, "");
  1.2779 +        nonstatic_word_space_offset = offset;
  1.2780 +        if( nonstatic_word_count > 0 ) {
  1.2781 +          nonstatic_word_count      -= 1;
  1.2782 +          nonstatic_word_space_count = 1; // Only one will fit
  1.2783 +          length -= BytesPerInt;
  1.2784 +          offset += BytesPerInt;
  1.2785 +        }
  1.2786 +        nonstatic_short_space_offset = offset;
  1.2787 +        while( length >= BytesPerShort && nonstatic_short_count > 0 ) {
  1.2788 +          nonstatic_short_count       -= 1;
  1.2789 +          nonstatic_short_space_count += 1;
  1.2790 +          length -= BytesPerShort;
  1.2791 +          offset += BytesPerShort;
  1.2792 +        }
  1.2793 +        nonstatic_byte_space_offset = offset;
  1.2794 +        while( length > 0 && nonstatic_byte_count > 0 ) {
  1.2795 +          nonstatic_byte_count       -= 1;
  1.2796 +          nonstatic_byte_space_count += 1;
  1.2797 +          length -= 1;
  1.2798 +        }
  1.2799 +        // Allocate oop field in the gap if there are no other fields for that.
  1.2800 +        nonstatic_oop_space_offset = offset;
  1.2801 +        if( length >= oopSize && nonstatic_oop_count > 0 &&
  1.2802 +            allocation_style != 0 ) { // when oop fields not first
  1.2803 +          nonstatic_oop_count      -= 1;
  1.2804 +          nonstatic_oop_space_count = 1; // Only one will fit
  1.2805 +          length -= oopSize;
  1.2806 +          offset += oopSize;
  1.2807 +        }
  1.2808 +      }
  1.2809 +    }
  1.2810 +
  1.2811 +    next_nonstatic_word_offset  = next_nonstatic_double_offset +
  1.2812 +                                  (nonstatic_double_count * BytesPerLong);
  1.2813 +    next_nonstatic_short_offset = next_nonstatic_word_offset +
  1.2814 +                                  (nonstatic_word_count * BytesPerInt);
  1.2815 +    next_nonstatic_byte_offset  = next_nonstatic_short_offset +
  1.2816 +                                  (nonstatic_short_count * BytesPerShort);
  1.2817 +
  1.2818 +    int notaligned_offset;
  1.2819 +    if( allocation_style == 0 ) {
  1.2820 +      notaligned_offset = next_nonstatic_byte_offset + nonstatic_byte_count;
  1.2821 +    } else { // allocation_style == 1
  1.2822 +      next_nonstatic_oop_offset = next_nonstatic_byte_offset + nonstatic_byte_count;
  1.2823 +      if( nonstatic_oop_count > 0 ) {
  1.2824 +        notaligned_offset = next_nonstatic_oop_offset;
  1.2825 +        next_nonstatic_oop_offset = align_size_up(next_nonstatic_oop_offset, oopSize);
  1.2826 +      }
  1.2827 +      notaligned_offset = next_nonstatic_oop_offset + (nonstatic_oop_count * oopSize);
  1.2828 +    }
  1.2829 +    next_nonstatic_type_offset = align_size_up(notaligned_offset, wordSize );
  1.2830 +    nonstatic_field_size = nonstatic_field_size + ((next_nonstatic_type_offset
  1.2831 +                                      - first_nonstatic_field_offset)/wordSize);
  1.2832 +
  1.2833 +    // Iterate over fields again and compute correct offsets.
  1.2834 +    // The field allocation type was temporarily stored in the offset slot.
  1.2835 +    // oop fields are located before non-oop fields (static and non-static).
  1.2836 +    int len = fields->length();
  1.2837 +    for (int i = 0; i < len; i += instanceKlass::next_offset) {
  1.2838 +      int real_offset;
  1.2839 +      FieldAllocationType atype = (FieldAllocationType) fields->ushort_at(i+4);
  1.2840 +      switch (atype) {
  1.2841 +        case STATIC_OOP:
  1.2842 +          real_offset = next_static_oop_offset;
  1.2843 +          next_static_oop_offset += oopSize;
  1.2844 +          break;
  1.2845 +        case STATIC_BYTE:
  1.2846 +          real_offset = next_static_byte_offset;
  1.2847 +          next_static_byte_offset += 1;
  1.2848 +          break;
  1.2849 +        case STATIC_SHORT:
  1.2850 +          real_offset = next_static_short_offset;
  1.2851 +          next_static_short_offset += BytesPerShort;
  1.2852 +          break;
  1.2853 +        case STATIC_WORD:
  1.2854 +          real_offset = next_static_word_offset;
  1.2855 +          next_static_word_offset += BytesPerInt;
  1.2856 +          break;
  1.2857 +        case STATIC_ALIGNED_DOUBLE:
  1.2858 +        case STATIC_DOUBLE:
  1.2859 +          real_offset = next_static_double_offset;
  1.2860 +          next_static_double_offset += BytesPerLong;
  1.2861 +          break;
  1.2862 +        case NONSTATIC_OOP:
  1.2863 +          if( nonstatic_oop_space_count > 0 ) {
  1.2864 +            real_offset = nonstatic_oop_space_offset;
  1.2865 +            nonstatic_oop_space_offset += oopSize;
  1.2866 +            nonstatic_oop_space_count  -= 1;
  1.2867 +          } else {
  1.2868 +            real_offset = next_nonstatic_oop_offset;
  1.2869 +            next_nonstatic_oop_offset += oopSize;
  1.2870 +          }
  1.2871 +          // Update oop maps
  1.2872 +          if( nonstatic_oop_map_count > 0 &&
  1.2873 +              nonstatic_oop_offsets[nonstatic_oop_map_count - 1] ==
  1.2874 +              (u2)(real_offset - nonstatic_oop_length[nonstatic_oop_map_count - 1] * oopSize) ) {
  1.2875 +            // Extend current oop map
  1.2876 +            nonstatic_oop_length[nonstatic_oop_map_count - 1] += 1;
  1.2877 +          } else {
  1.2878 +            // Create new oop map
  1.2879 +            nonstatic_oop_offsets[nonstatic_oop_map_count] = (u2)real_offset;
  1.2880 +            nonstatic_oop_length [nonstatic_oop_map_count] = 1;
  1.2881 +            nonstatic_oop_map_count += 1;
  1.2882 +            if( first_nonstatic_oop_offset == 0 ) { // Undefined
  1.2883 +              first_nonstatic_oop_offset = real_offset;
  1.2884 +            }
  1.2885 +          }
  1.2886 +          break;
  1.2887 +        case NONSTATIC_BYTE:
  1.2888 +          if( nonstatic_byte_space_count > 0 ) {
  1.2889 +            real_offset = nonstatic_byte_space_offset;
  1.2890 +            nonstatic_byte_space_offset += 1;
  1.2891 +            nonstatic_byte_space_count  -= 1;
  1.2892 +          } else {
  1.2893 +            real_offset = next_nonstatic_byte_offset;
  1.2894 +            next_nonstatic_byte_offset += 1;
  1.2895 +          }
  1.2896 +          break;
  1.2897 +        case NONSTATIC_SHORT:
  1.2898 +          if( nonstatic_short_space_count > 0 ) {
  1.2899 +            real_offset = nonstatic_short_space_offset;
  1.2900 +            nonstatic_short_space_offset += BytesPerShort;
  1.2901 +            nonstatic_short_space_count  -= 1;
  1.2902 +          } else {
  1.2903 +            real_offset = next_nonstatic_short_offset;
  1.2904 +            next_nonstatic_short_offset += BytesPerShort;
  1.2905 +          }
  1.2906 +          break;
  1.2907 +        case NONSTATIC_WORD:
  1.2908 +          if( nonstatic_word_space_count > 0 ) {
  1.2909 +            real_offset = nonstatic_word_space_offset;
  1.2910 +            nonstatic_word_space_offset += BytesPerInt;
  1.2911 +            nonstatic_word_space_count  -= 1;
  1.2912 +          } else {
  1.2913 +            real_offset = next_nonstatic_word_offset;
  1.2914 +            next_nonstatic_word_offset += BytesPerInt;
  1.2915 +          }
  1.2916 +          break;
  1.2917 +        case NONSTATIC_ALIGNED_DOUBLE:
  1.2918 +        case NONSTATIC_DOUBLE:
  1.2919 +          real_offset = next_nonstatic_double_offset;
  1.2920 +          next_nonstatic_double_offset += BytesPerLong;
  1.2921 +          break;
  1.2922 +        default:
  1.2923 +          ShouldNotReachHere();
  1.2924 +      }
  1.2925 +      fields->short_at_put(i+4, extract_low_short_from_int(real_offset) );
  1.2926 +      fields->short_at_put(i+5, extract_high_short_from_int(real_offset) );
  1.2927 +    }
  1.2928 +
  1.2929 +    // Size of instances
  1.2930 +    int instance_size;
  1.2931 +
  1.2932 +    instance_size = align_object_size(next_nonstatic_type_offset / wordSize);
  1.2933 +
  1.2934 +    assert(instance_size == align_object_size(instanceOopDesc::header_size() + nonstatic_field_size), "consistent layout helper value");
  1.2935 +
  1.2936 +    // Size of non-static oop map blocks (in words) allocated at end of klass
  1.2937 +    int nonstatic_oop_map_size = compute_oop_map_size(super_klass, nonstatic_oop_map_count, first_nonstatic_oop_offset);
  1.2938 +
  1.2939 +    // Compute reference type
  1.2940 +    ReferenceType rt;
  1.2941 +    if (super_klass() == NULL) {
  1.2942 +      rt = REF_NONE;
  1.2943 +    } else {
  1.2944 +      rt = super_klass->reference_type();
  1.2945 +    }
  1.2946 +
  1.2947 +    // We can now create the basic klassOop for this klass
  1.2948 +    klassOop ik = oopFactory::new_instanceKlass(
  1.2949 +                                    vtable_size, itable_size,
  1.2950 +                                    static_field_size, nonstatic_oop_map_size,
  1.2951 +                                    rt, CHECK_(nullHandle));
  1.2952 +    instanceKlassHandle this_klass (THREAD, ik);
  1.2953 +
  1.2954 +    assert(this_klass->static_field_size() == static_field_size &&
  1.2955 +           this_klass->nonstatic_oop_map_size() == nonstatic_oop_map_size, "sanity check");
  1.2956 +
  1.2957 +    // Fill in information already parsed
  1.2958 +    this_klass->set_access_flags(access_flags);
  1.2959 +    jint lh = Klass::instance_layout_helper(instance_size, false);
  1.2960 +    this_klass->set_layout_helper(lh);
  1.2961 +    assert(this_klass->oop_is_instance(), "layout is correct");
  1.2962 +    assert(this_klass->size_helper() == instance_size, "correct size_helper");
  1.2963 +    // Not yet: supers are done below to support the new subtype-checking fields
  1.2964 +    //this_klass->set_super(super_klass());
  1.2965 +    this_klass->set_class_loader(class_loader());
  1.2966 +    this_klass->set_nonstatic_field_size(nonstatic_field_size);
  1.2967 +    this_klass->set_static_oop_field_size(fac.static_oop_count);
  1.2968 +    cp->set_pool_holder(this_klass());
  1.2969 +    this_klass->set_constants(cp());
  1.2970 +    this_klass->set_local_interfaces(local_interfaces());
  1.2971 +    this_klass->set_fields(fields());
  1.2972 +    this_klass->set_methods(methods());
  1.2973 +    if (has_final_method) {
  1.2974 +      this_klass->set_has_final_method();
  1.2975 +    }
  1.2976 +    this_klass->set_method_ordering(method_ordering());
  1.2977 +    this_klass->set_initial_method_idnum(methods->length());
  1.2978 +    this_klass->set_name(cp->klass_name_at(this_class_index));
  1.2979 +    this_klass->set_protection_domain(protection_domain());
  1.2980 +    this_klass->set_fields_annotations(fields_annotations());
  1.2981 +    this_klass->set_methods_annotations(methods_annotations());
  1.2982 +    this_klass->set_methods_parameter_annotations(methods_parameter_annotations());
  1.2983 +    this_klass->set_methods_default_annotations(methods_default_annotations());
  1.2984 +
  1.2985 +    this_klass->set_minor_version(minor_version);
  1.2986 +    this_klass->set_major_version(major_version);
  1.2987 +
  1.2988 +    if (cached_class_file_bytes != NULL) {
  1.2989 +      // JVMTI: we have an instanceKlass now, tell it about the cached bytes
  1.2990 +      this_klass->set_cached_class_file(cached_class_file_bytes,
  1.2991 +                                        cached_class_file_length);
  1.2992 +    }
  1.2993 +
  1.2994 +    // Miranda methods
  1.2995 +    if ((num_miranda_methods > 0) ||
  1.2996 +        // if this class introduced new miranda methods or
  1.2997 +        (super_klass.not_null() && (super_klass->has_miranda_methods()))
  1.2998 +        // super class exists and this class inherited miranda methods
  1.2999 +        ) {
  1.3000 +      this_klass->set_has_miranda_methods(); // then set a flag
  1.3001 +    }
  1.3002 +
  1.3003 +    // Additional attributes
  1.3004 +    parse_classfile_attributes(cp, this_klass, CHECK_(nullHandle));
  1.3005 +
  1.3006 +    // Make sure this is the end of class file stream
  1.3007 +    guarantee_property(cfs->at_eos(), "Extra bytes at the end of class file %s", CHECK_(nullHandle));
  1.3008 +
  1.3009 +    // Initialize static fields
  1.3010 +    this_klass->do_local_static_fields(&initialize_static_field, CHECK_(nullHandle));
  1.3011 +
  1.3012 +    // VerifyOops believes that once this has been set, the object is completely loaded.
  1.3013 +    // Compute transitive closure of interfaces this class implements
  1.3014 +    this_klass->set_transitive_interfaces(transitive_interfaces());
  1.3015 +
  1.3016 +    // Fill in information needed to compute superclasses.
  1.3017 +    this_klass->initialize_supers(super_klass(), CHECK_(nullHandle));
  1.3018 +
  1.3019 +    // Initialize itable offset tables
  1.3020 +    klassItable::setup_itable_offset_table(this_klass);
  1.3021 +
  1.3022 +    // Do final class setup
  1.3023 +    fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_length);
  1.3024 +
  1.3025 +    set_precomputed_flags(this_klass);
  1.3026 +
  1.3027 +    // reinitialize modifiers, using the InnerClasses attribute
  1.3028 +    int computed_modifiers = this_klass->compute_modifier_flags(CHECK_(nullHandle));
  1.3029 +    this_klass->set_modifier_flags(computed_modifiers);
  1.3030 +
  1.3031 +    // check if this class can access its super class
  1.3032 +    check_super_class_access(this_klass, CHECK_(nullHandle));
  1.3033 +
  1.3034 +    // check if this class can access its superinterfaces
  1.3035 +    check_super_interface_access(this_klass, CHECK_(nullHandle));
  1.3036 +
  1.3037 +    // check if this class overrides any final method
  1.3038 +    check_final_method_override(this_klass, CHECK_(nullHandle));
  1.3039 +
  1.3040 +    // check that if this class is an interface then it doesn't have static methods
  1.3041 +    if (this_klass->is_interface()) {
  1.3042 +      check_illegal_static_method(this_klass, CHECK_(nullHandle));
  1.3043 +    }
  1.3044 +
  1.3045 +    ClassLoadingService::notify_class_loaded(instanceKlass::cast(this_klass()),
  1.3046 +                                             false /* not shared class */);
  1.3047 +
  1.3048 +    if (TraceClassLoading) {
  1.3049 +      // print in a single call to reduce interleaving of output
  1.3050 +      if (cfs->source() != NULL) {
  1.3051 +        tty->print("[Loaded %s from %s]\n", this_klass->external_name(),
  1.3052 +                   cfs->source());
  1.3053 +      } else if (class_loader.is_null()) {
  1.3054 +        if (THREAD->is_Java_thread()) {
  1.3055 +          klassOop caller = ((JavaThread*)THREAD)->security_get_caller_class(1);
  1.3056 +          tty->print("[Loaded %s by instance of %s]\n",
  1.3057 +                     this_klass->external_name(),
  1.3058 +                     instanceKlass::cast(caller)->external_name());
  1.3059 +        } else {
  1.3060 +          tty->print("[Loaded %s]\n", this_klass->external_name());
  1.3061 +        }
  1.3062 +      } else {
  1.3063 +        ResourceMark rm;
  1.3064 +        tty->print("[Loaded %s from %s]\n", this_klass->external_name(),
  1.3065 +                   instanceKlass::cast(class_loader->klass())->external_name());
  1.3066 +      }
  1.3067 +    }
  1.3068 +
  1.3069 +    if (TraceClassResolution) {
  1.3070 +      // print out the superclass.
  1.3071 +      const char * from = Klass::cast(this_klass())->external_name();
  1.3072 +      if (this_klass->java_super() != NULL) {
  1.3073 +        tty->print("RESOLVE %s %s\n", from, instanceKlass::cast(this_klass->java_super())->external_name());
  1.3074 +      }
  1.3075 +      // print out each of the interface classes referred to by this class.
  1.3076 +      objArrayHandle local_interfaces(THREAD, this_klass->local_interfaces());
  1.3077 +      if (!local_interfaces.is_null()) {
  1.3078 +        int length = local_interfaces->length();
  1.3079 +        for (int i = 0; i < length; i++) {
  1.3080 +          klassOop k = klassOop(local_interfaces->obj_at(i));
  1.3081 +          instanceKlass* to_class = instanceKlass::cast(k);
  1.3082 +          const char * to = to_class->external_name();
  1.3083 +          tty->print("RESOLVE %s %s\n", from, to);
  1.3084 +        }
  1.3085 +      }
  1.3086 +    }
  1.3087 +
  1.3088 +#ifndef PRODUCT
  1.3089 +    if( PrintCompactFieldsSavings ) {
  1.3090 +      if( nonstatic_field_size < orig_nonstatic_field_size ) {
  1.3091 +        tty->print("[Saved %d of %3d words in %s]\n",
  1.3092 +                 orig_nonstatic_field_size - nonstatic_field_size,
  1.3093 +                 orig_nonstatic_field_size, this_klass->external_name());
  1.3094 +      } else if( nonstatic_field_size > orig_nonstatic_field_size ) {
  1.3095 +        tty->print("[Wasted %d over %3d words in %s]\n",
  1.3096 +                 nonstatic_field_size - orig_nonstatic_field_size,
  1.3097 +                 orig_nonstatic_field_size, this_klass->external_name());
  1.3098 +      }
  1.3099 +    }
  1.3100 +#endif
  1.3101 +
  1.3102 +    // preserve result across HandleMark
  1.3103 +    preserve_this_klass = this_klass();
  1.3104 +  }
  1.3105 +
  1.3106 +  // Create new handle outside HandleMark
  1.3107 +  instanceKlassHandle this_klass (THREAD, preserve_this_klass);
  1.3108 +  debug_only(this_klass->as_klassOop()->verify();)
  1.3109 +
  1.3110 +  return this_klass;
  1.3111 +}
  1.3112 +
  1.3113 +
  1.3114 +int ClassFileParser::compute_oop_map_size(instanceKlassHandle super, int nonstatic_oop_map_count, int first_nonstatic_oop_offset) {
  1.3115 +  int map_size = super.is_null() ? 0 : super->nonstatic_oop_map_size();
  1.3116 +  if (nonstatic_oop_map_count > 0) {
  1.3117 +    // We have oops to add to map
  1.3118 +    if (map_size == 0) {
  1.3119 +      map_size = nonstatic_oop_map_count;
  1.3120 +    } else {
  1.3121 +      // Check whether we should add a new map block or whether the last one can be extended
  1.3122 +      OopMapBlock* first_map = super->start_of_nonstatic_oop_maps();
  1.3123 +      OopMapBlock* last_map = first_map + map_size - 1;
  1.3124 +
  1.3125 +      int next_offset = last_map->offset() + (last_map->length() * oopSize);
  1.3126 +      if (next_offset == first_nonstatic_oop_offset) {
  1.3127 +        // There is no gap bettwen superklass's last oop field and first
  1.3128 +        // local oop field, merge maps.
  1.3129 +        nonstatic_oop_map_count -= 1;
  1.3130 +      } else {
  1.3131 +        // Superklass didn't end with a oop field, add extra maps
  1.3132 +        assert(next_offset<first_nonstatic_oop_offset, "just checking");
  1.3133 +      }
  1.3134 +      map_size += nonstatic_oop_map_count;
  1.3135 +    }
  1.3136 +  }
  1.3137 +  return map_size;
  1.3138 +}
  1.3139 +
  1.3140 +
  1.3141 +void ClassFileParser::fill_oop_maps(instanceKlassHandle k,
  1.3142 +                        int nonstatic_oop_map_count,
  1.3143 +                        u2* nonstatic_oop_offsets, u2* nonstatic_oop_length) {
  1.3144 +  OopMapBlock* this_oop_map = k->start_of_nonstatic_oop_maps();
  1.3145 +  OopMapBlock* last_oop_map = this_oop_map + k->nonstatic_oop_map_size();
  1.3146 +  instanceKlass* super = k->superklass();
  1.3147 +  if (super != NULL) {
  1.3148 +    int super_oop_map_size     = super->nonstatic_oop_map_size();
  1.3149 +    OopMapBlock* super_oop_map = super->start_of_nonstatic_oop_maps();
  1.3150 +    // Copy maps from superklass
  1.3151 +    while (super_oop_map_size-- > 0) {
  1.3152 +      *this_oop_map++ = *super_oop_map++;
  1.3153 +    }
  1.3154 +  }
  1.3155 +  if (nonstatic_oop_map_count > 0) {
  1.3156 +    if (this_oop_map + nonstatic_oop_map_count > last_oop_map) {
  1.3157 +      // Calculated in compute_oop_map_size() number of oop maps is less then
  1.3158 +      // collected oop maps since there is no gap between superklass's last oop
  1.3159 +      // field and first local oop field. Extend the last oop map copied
  1.3160 +      // from the superklass instead of creating new one.
  1.3161 +      nonstatic_oop_map_count--;
  1.3162 +      nonstatic_oop_offsets++;
  1.3163 +      this_oop_map--;
  1.3164 +      this_oop_map->set_length(this_oop_map->length() + *nonstatic_oop_length++);
  1.3165 +      this_oop_map++;
  1.3166 +    }
  1.3167 +    assert((this_oop_map + nonstatic_oop_map_count) == last_oop_map, "just checking");
  1.3168 +    // Add new map blocks, fill them
  1.3169 +    while (nonstatic_oop_map_count-- > 0) {
  1.3170 +      this_oop_map->set_offset(*nonstatic_oop_offsets++);
  1.3171 +      this_oop_map->set_length(*nonstatic_oop_length++);
  1.3172 +      this_oop_map++;
  1.3173 +    }
  1.3174 +  }
  1.3175 +}
  1.3176 +
  1.3177 +
  1.3178 +void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
  1.3179 +  klassOop super = k->super();
  1.3180 +
  1.3181 +  // Check if this klass has an empty finalize method (i.e. one with return bytecode only),
  1.3182 +  // in which case we don't have to register objects as finalizable
  1.3183 +  if (!_has_empty_finalizer) {
  1.3184 +    if (_has_finalizer ||
  1.3185 +        (super != NULL && super->klass_part()->has_finalizer())) {
  1.3186 +      k->set_has_finalizer();
  1.3187 +    }
  1.3188 +  }
  1.3189 +
  1.3190 +#ifdef ASSERT
  1.3191 +  bool f = false;
  1.3192 +  methodOop m = k->lookup_method(vmSymbols::finalize_method_name(),
  1.3193 +                                 vmSymbols::void_method_signature());
  1.3194 +  if (m != NULL && !m->is_empty_method()) {
  1.3195 +    f = true;
  1.3196 +  }
  1.3197 +  assert(f == k->has_finalizer(), "inconsistent has_finalizer");
  1.3198 +#endif
  1.3199 +
  1.3200 +  // Check if this klass supports the java.lang.Cloneable interface
  1.3201 +  if (SystemDictionary::cloneable_klass_loaded()) {
  1.3202 +    if (k->is_subtype_of(SystemDictionary::cloneable_klass())) {
  1.3203 +      k->set_is_cloneable();
  1.3204 +    }
  1.3205 +  }
  1.3206 +
  1.3207 +  // Check if this klass has a vanilla default constructor
  1.3208 +  if (super == NULL) {
  1.3209 +    // java.lang.Object has empty default constructor
  1.3210 +    k->set_has_vanilla_constructor();
  1.3211 +  } else {
  1.3212 +    if (Klass::cast(super)->has_vanilla_constructor() &&
  1.3213 +        _has_vanilla_constructor) {
  1.3214 +      k->set_has_vanilla_constructor();
  1.3215 +    }
  1.3216 +#ifdef ASSERT
  1.3217 +    bool v = false;
  1.3218 +    if (Klass::cast(super)->has_vanilla_constructor()) {
  1.3219 +      methodOop constructor = k->find_method(vmSymbols::object_initializer_name(
  1.3220 +), vmSymbols::void_method_signature());
  1.3221 +      if (constructor != NULL && constructor->is_vanilla_constructor()) {
  1.3222 +        v = true;
  1.3223 +      }
  1.3224 +    }
  1.3225 +    assert(v == k->has_vanilla_constructor(), "inconsistent has_vanilla_constructor");
  1.3226 +#endif
  1.3227 +  }
  1.3228 +
  1.3229 +  // If it cannot be fast-path allocated, set a bit in the layout helper.
  1.3230 +  // See documentation of instanceKlass::can_be_fastpath_allocated().
  1.3231 +  assert(k->size_helper() > 0, "layout_helper is initialized");
  1.3232 +  if ((!RegisterFinalizersAtInit && k->has_finalizer())
  1.3233 +      || k->is_abstract() || k->is_interface()
  1.3234 +      || (k->name() == vmSymbols::java_lang_Class()
  1.3235 +          && k->class_loader() == NULL)
  1.3236 +      || k->size_helper() >= FastAllocateSizeLimit) {
  1.3237 +    // Forbid fast-path allocation.
  1.3238 +    jint lh = Klass::instance_layout_helper(k->size_helper(), true);
  1.3239 +    k->set_layout_helper(lh);
  1.3240 +  }
  1.3241 +}
  1.3242 +
  1.3243 +
  1.3244 +// utility method for appending and array with check for duplicates
  1.3245 +
  1.3246 +void append_interfaces(objArrayHandle result, int& index, objArrayOop ifs) {
  1.3247 +  // iterate over new interfaces
  1.3248 +  for (int i = 0; i < ifs->length(); i++) {
  1.3249 +    oop e = ifs->obj_at(i);
  1.3250 +    assert(e->is_klass() && instanceKlass::cast(klassOop(e))->is_interface(), "just checking");
  1.3251 +    // check for duplicates
  1.3252 +    bool duplicate = false;
  1.3253 +    for (int j = 0; j < index; j++) {
  1.3254 +      if (result->obj_at(j) == e) {
  1.3255 +        duplicate = true;
  1.3256 +        break;
  1.3257 +      }
  1.3258 +    }
  1.3259 +    // add new interface
  1.3260 +    if (!duplicate) {
  1.3261 +      result->obj_at_put(index++, e);
  1.3262 +    }
  1.3263 +  }
  1.3264 +}
  1.3265 +
  1.3266 +objArrayHandle ClassFileParser::compute_transitive_interfaces(instanceKlassHandle super, objArrayHandle local_ifs, TRAPS) {
  1.3267 +  // Compute maximum size for transitive interfaces
  1.3268 +  int max_transitive_size = 0;
  1.3269 +  int super_size = 0;
  1.3270 +  // Add superclass transitive interfaces size
  1.3271 +  if (super.not_null()) {
  1.3272 +    super_size = super->transitive_interfaces()->length();
  1.3273 +    max_transitive_size += super_size;
  1.3274 +  }
  1.3275 +  // Add local interfaces' super interfaces
  1.3276 +  int local_size = local_ifs->length();
  1.3277 +  for (int i = 0; i < local_size; i++) {
  1.3278 +    klassOop l = klassOop(local_ifs->obj_at(i));
  1.3279 +    max_transitive_size += instanceKlass::cast(l)->transitive_interfaces()->length();
  1.3280 +  }
  1.3281 +  // Finally add local interfaces
  1.3282 +  max_transitive_size += local_size;
  1.3283 +  // Construct array
  1.3284 +  objArrayHandle result;
  1.3285 +  if (max_transitive_size == 0) {
  1.3286 +    // no interfaces, use canonicalized array
  1.3287 +    result = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  1.3288 +  } else if (max_transitive_size == super_size) {
  1.3289 +    // no new local interfaces added, share superklass' transitive interface array
  1.3290 +    result = objArrayHandle(THREAD, super->transitive_interfaces());
  1.3291 +  } else if (max_transitive_size == local_size) {
  1.3292 +    // only local interfaces added, share local interface array
  1.3293 +    result = local_ifs;
  1.3294 +  } else {
  1.3295 +    objArrayHandle nullHandle;
  1.3296 +    objArrayOop new_objarray = oopFactory::new_system_objArray(max_transitive_size, CHECK_(nullHandle));
  1.3297 +    result = objArrayHandle(THREAD, new_objarray);
  1.3298 +    int index = 0;
  1.3299 +    // Copy down from superclass
  1.3300 +    if (super.not_null()) {
  1.3301 +      append_interfaces(result, index, super->transitive_interfaces());
  1.3302 +    }
  1.3303 +    // Copy down from local interfaces' superinterfaces
  1.3304 +    for (int i = 0; i < local_ifs->length(); i++) {
  1.3305 +      klassOop l = klassOop(local_ifs->obj_at(i));
  1.3306 +      append_interfaces(result, index, instanceKlass::cast(l)->transitive_interfaces());
  1.3307 +    }
  1.3308 +    // Finally add local interfaces
  1.3309 +    append_interfaces(result, index, local_ifs());
  1.3310 +
  1.3311 +    // Check if duplicates were removed
  1.3312 +    if (index != max_transitive_size) {
  1.3313 +      assert(index < max_transitive_size, "just checking");
  1.3314 +      objArrayOop new_result = oopFactory::new_system_objArray(index, CHECK_(nullHandle));
  1.3315 +      for (int i = 0; i < index; i++) {
  1.3316 +        oop e = result->obj_at(i);
  1.3317 +        assert(e != NULL, "just checking");
  1.3318 +        new_result->obj_at_put(i, e);
  1.3319 +      }
  1.3320 +      result = objArrayHandle(THREAD, new_result);
  1.3321 +    }
  1.3322 +  }
  1.3323 +  return result;
  1.3324 +}
  1.3325 +
  1.3326 +
  1.3327 +void ClassFileParser::check_super_class_access(instanceKlassHandle this_klass, TRAPS) {
  1.3328 +  klassOop super = this_klass->super();
  1.3329 +  if ((super != NULL) &&
  1.3330 +      (!Reflection::verify_class_access(this_klass->as_klassOop(), super, false))) {
  1.3331 +    ResourceMark rm(THREAD);
  1.3332 +    Exceptions::fthrow(
  1.3333 +      THREAD_AND_LOCATION,
  1.3334 +      vmSymbolHandles::java_lang_IllegalAccessError(),
  1.3335 +      "class %s cannot access its superclass %s",
  1.3336 +      this_klass->external_name(),
  1.3337 +      instanceKlass::cast(super)->external_name()
  1.3338 +    );
  1.3339 +    return;
  1.3340 +  }
  1.3341 +}
  1.3342 +
  1.3343 +
  1.3344 +void ClassFileParser::check_super_interface_access(instanceKlassHandle this_klass, TRAPS) {
  1.3345 +  objArrayHandle local_interfaces (THREAD, this_klass->local_interfaces());
  1.3346 +  int lng = local_interfaces->length();
  1.3347 +  for (int i = lng - 1; i >= 0; i--) {
  1.3348 +    klassOop k = klassOop(local_interfaces->obj_at(i));
  1.3349 +    assert (k != NULL && Klass::cast(k)->is_interface(), "invalid interface");
  1.3350 +    if (!Reflection::verify_class_access(this_klass->as_klassOop(), k, false)) {
  1.3351 +      ResourceMark rm(THREAD);
  1.3352 +      Exceptions::fthrow(
  1.3353 +        THREAD_AND_LOCATION,
  1.3354 +        vmSymbolHandles::java_lang_IllegalAccessError(),
  1.3355 +        "class %s cannot access its superinterface %s",
  1.3356 +        this_klass->external_name(),
  1.3357 +        instanceKlass::cast(k)->external_name()
  1.3358 +      );
  1.3359 +      return;
  1.3360 +    }
  1.3361 +  }
  1.3362 +}
  1.3363 +
  1.3364 +
  1.3365 +void ClassFileParser::check_final_method_override(instanceKlassHandle this_klass, TRAPS) {
  1.3366 +  objArrayHandle methods (THREAD, this_klass->methods());
  1.3367 +  int num_methods = methods->length();
  1.3368 +
  1.3369 +  // go thru each method and check if it overrides a final method
  1.3370 +  for (int index = 0; index < num_methods; index++) {
  1.3371 +    methodOop m = (methodOop)methods->obj_at(index);
  1.3372 +
  1.3373 +    // skip private, static and <init> methods
  1.3374 +    if ((!m->is_private()) &&
  1.3375 +        (!m->is_static()) &&
  1.3376 +        (m->name() != vmSymbols::object_initializer_name())) {
  1.3377 +
  1.3378 +      symbolOop name = m->name();
  1.3379 +      symbolOop signature = m->signature();
  1.3380 +      klassOop k = this_klass->super();
  1.3381 +      methodOop super_m = NULL;
  1.3382 +      while (k != NULL) {
  1.3383 +        // skip supers that don't have final methods.
  1.3384 +        if (k->klass_part()->has_final_method()) {
  1.3385 +          // lookup a matching method in the super class hierarchy
  1.3386 +          super_m = instanceKlass::cast(k)->lookup_method(name, signature);
  1.3387 +          if (super_m == NULL) {
  1.3388 +            break; // didn't find any match; get out
  1.3389 +          }
  1.3390 +
  1.3391 +          if (super_m->is_final() &&
  1.3392 +              // matching method in super is final
  1.3393 +              (Reflection::verify_field_access(this_klass->as_klassOop(),
  1.3394 +                                               super_m->method_holder(),
  1.3395 +                                               super_m->method_holder(),
  1.3396 +                                               super_m->access_flags(), false))
  1.3397 +            // this class can access super final method and therefore override
  1.3398 +            ) {
  1.3399 +            ResourceMark rm(THREAD);
  1.3400 +            Exceptions::fthrow(
  1.3401 +              THREAD_AND_LOCATION,
  1.3402 +              vmSymbolHandles::java_lang_VerifyError(),
  1.3403 +              "class %s overrides final method %s.%s",
  1.3404 +              this_klass->external_name(),
  1.3405 +              name->as_C_string(),
  1.3406 +              signature->as_C_string()
  1.3407 +            );
  1.3408 +            return;
  1.3409 +          }
  1.3410 +
  1.3411 +          // continue to look from super_m's holder's super.
  1.3412 +          k = instanceKlass::cast(super_m->method_holder())->super();
  1.3413 +          continue;
  1.3414 +        }
  1.3415 +
  1.3416 +        k = k->klass_part()->super();
  1.3417 +      }
  1.3418 +    }
  1.3419 +  }
  1.3420 +}
  1.3421 +
  1.3422 +
  1.3423 +// assumes that this_klass is an interface
  1.3424 +void ClassFileParser::check_illegal_static_method(instanceKlassHandle this_klass, TRAPS) {
  1.3425 +  assert(this_klass->is_interface(), "not an interface");
  1.3426 +  objArrayHandle methods (THREAD, this_klass->methods());
  1.3427 +  int num_methods = methods->length();
  1.3428 +
  1.3429 +  for (int index = 0; index < num_methods; index++) {
  1.3430 +    methodOop m = (methodOop)methods->obj_at(index);
  1.3431 +    // if m is static and not the init method, throw a verify error
  1.3432 +    if ((m->is_static()) && (m->name() != vmSymbols::class_initializer_name())) {
  1.3433 +      ResourceMark rm(THREAD);
  1.3434 +      Exceptions::fthrow(
  1.3435 +        THREAD_AND_LOCATION,
  1.3436 +        vmSymbolHandles::java_lang_VerifyError(),
  1.3437 +        "Illegal static method %s in interface %s",
  1.3438 +        m->name()->as_C_string(),
  1.3439 +        this_klass->external_name()
  1.3440 +      );
  1.3441 +      return;
  1.3442 +    }
  1.3443 +  }
  1.3444 +}
  1.3445 +
  1.3446 +// utility methods for format checking
  1.3447 +
  1.3448 +void ClassFileParser::verify_legal_class_modifiers(jint flags, TRAPS) {
  1.3449 +  if (!_need_verify) { return; }
  1.3450 +
  1.3451 +  const bool is_interface  = (flags & JVM_ACC_INTERFACE)  != 0;
  1.3452 +  const bool is_abstract   = (flags & JVM_ACC_ABSTRACT)   != 0;
  1.3453 +  const bool is_final      = (flags & JVM_ACC_FINAL)      != 0;
  1.3454 +  const bool is_super      = (flags & JVM_ACC_SUPER)      != 0;
  1.3455 +  const bool is_enum       = (flags & JVM_ACC_ENUM)       != 0;
  1.3456 +  const bool is_annotation = (flags & JVM_ACC_ANNOTATION) != 0;
  1.3457 +  const bool major_gte_15  = _major_version >= JAVA_1_5_VERSION;
  1.3458 +
  1.3459 +  if ((is_abstract && is_final) ||
  1.3460 +      (is_interface && !is_abstract) ||
  1.3461 +      (is_interface && major_gte_15 && (is_super || is_enum)) ||
  1.3462 +      (!is_interface && major_gte_15 && is_annotation)) {
  1.3463 +    ResourceMark rm(THREAD);
  1.3464 +    Exceptions::fthrow(
  1.3465 +      THREAD_AND_LOCATION,
  1.3466 +      vmSymbolHandles::java_lang_ClassFormatError(),
  1.3467 +      "Illegal class modifiers in class %s: 0x%X",
  1.3468 +      _class_name->as_C_string(), flags
  1.3469 +    );
  1.3470 +    return;
  1.3471 +  }
  1.3472 +}
  1.3473 +
  1.3474 +bool ClassFileParser::has_illegal_visibility(jint flags) {
  1.3475 +  const bool is_public    = (flags & JVM_ACC_PUBLIC)    != 0;
  1.3476 +  const bool is_protected = (flags & JVM_ACC_PROTECTED) != 0;
  1.3477 +  const bool is_private   = (flags & JVM_ACC_PRIVATE)   != 0;
  1.3478 +
  1.3479 +  return ((is_public && is_protected) ||
  1.3480 +          (is_public && is_private) ||
  1.3481 +          (is_protected && is_private));
  1.3482 +}
  1.3483 +
  1.3484 +bool ClassFileParser::is_supported_version(u2 major, u2 minor) {
  1.3485 +  return (major >= JAVA_MIN_SUPPORTED_VERSION) &&
  1.3486 +         (major <= JAVA_MAX_SUPPORTED_VERSION) &&
  1.3487 +         ((major != JAVA_MAX_SUPPORTED_VERSION) ||
  1.3488 +          (minor <= JAVA_MAX_SUPPORTED_MINOR_VERSION));
  1.3489 +}
  1.3490 +
  1.3491 +void ClassFileParser::verify_legal_field_modifiers(
  1.3492 +    jint flags, bool is_interface, TRAPS) {
  1.3493 +  if (!_need_verify) { return; }
  1.3494 +
  1.3495 +  const bool is_public    = (flags & JVM_ACC_PUBLIC)    != 0;
  1.3496 +  const bool is_protected = (flags & JVM_ACC_PROTECTED) != 0;
  1.3497 +  const bool is_private   = (flags & JVM_ACC_PRIVATE)   != 0;
  1.3498 +  const bool is_static    = (flags & JVM_ACC_STATIC)    != 0;
  1.3499 +  const bool is_final     = (flags & JVM_ACC_FINAL)     != 0;
  1.3500 +  const bool is_volatile  = (flags & JVM_ACC_VOLATILE)  != 0;
  1.3501 +  const bool is_transient = (flags & JVM_ACC_TRANSIENT) != 0;
  1.3502 +  const bool is_enum      = (flags & JVM_ACC_ENUM)      != 0;
  1.3503 +  const bool major_gte_15 = _major_version >= JAVA_1_5_VERSION;
  1.3504 +
  1.3505 +  bool is_illegal = false;
  1.3506 +
  1.3507 +  if (is_interface) {
  1.3508 +    if (!is_public || !is_static || !is_final || is_private ||
  1.3509 +        is_protected || is_volatile || is_transient ||
  1.3510 +        (major_gte_15 && is_enum)) {
  1.3511 +      is_illegal = true;
  1.3512 +    }
  1.3513 +  } else { // not interface
  1.3514 +    if (has_illegal_visibility(flags) || (is_final && is_volatile)) {
  1.3515 +      is_illegal = true;
  1.3516 +    }
  1.3517 +  }
  1.3518 +
  1.3519 +  if (is_illegal) {
  1.3520 +    ResourceMark rm(THREAD);
  1.3521 +    Exceptions::fthrow(
  1.3522 +      THREAD_AND_LOCATION,
  1.3523 +      vmSymbolHandles::java_lang_ClassFormatError(),
  1.3524 +      "Illegal field modifiers in class %s: 0x%X",
  1.3525 +      _class_name->as_C_string(), flags);
  1.3526 +    return;
  1.3527 +  }
  1.3528 +}
  1.3529 +
  1.3530 +void ClassFileParser::verify_legal_method_modifiers(
  1.3531 +    jint flags, bool is_interface, symbolHandle name, TRAPS) {
  1.3532 +  if (!_need_verify) { return; }
  1.3533 +
  1.3534 +  const bool is_public       = (flags & JVM_ACC_PUBLIC)       != 0;
  1.3535 +  const bool is_private      = (flags & JVM_ACC_PRIVATE)      != 0;
  1.3536 +  const bool is_static       = (flags & JVM_ACC_STATIC)       != 0;
  1.3537 +  const bool is_final        = (flags & JVM_ACC_FINAL)        != 0;
  1.3538 +  const bool is_native       = (flags & JVM_ACC_NATIVE)       != 0;
  1.3539 +  const bool is_abstract     = (flags & JVM_ACC_ABSTRACT)     != 0;
  1.3540 +  const bool is_bridge       = (flags & JVM_ACC_BRIDGE)       != 0;
  1.3541 +  const bool is_strict       = (flags & JVM_ACC_STRICT)       != 0;
  1.3542 +  const bool is_synchronized = (flags & JVM_ACC_SYNCHRONIZED) != 0;
  1.3543 +  const bool major_gte_15    = _major_version >= JAVA_1_5_VERSION;
  1.3544 +  const bool is_initializer  = (name == vmSymbols::object_initializer_name());
  1.3545 +
  1.3546 +  bool is_illegal = false;
  1.3547 +
  1.3548 +  if (is_interface) {
  1.3549 +    if (!is_abstract || !is_public || is_static || is_final ||
  1.3550 +        is_native || (major_gte_15 && (is_synchronized || is_strict))) {
  1.3551 +      is_illegal = true;
  1.3552 +    }
  1.3553 +  } else { // not interface
  1.3554 +    if (is_initializer) {
  1.3555 +      if (is_static || is_final || is_synchronized || is_native ||
  1.3556 +          is_abstract || (major_gte_15 && is_bridge)) {
  1.3557 +        is_illegal = true;
  1.3558 +      }
  1.3559 +    } else { // not initializer
  1.3560 +      if (is_abstract) {
  1.3561 +        if ((is_final || is_native || is_private || is_static ||
  1.3562 +            (major_gte_15 && (is_synchronized || is_strict)))) {
  1.3563 +          is_illegal = true;
  1.3564 +        }
  1.3565 +      }
  1.3566 +      if (has_illegal_visibility(flags)) {
  1.3567 +        is_illegal = true;
  1.3568 +      }
  1.3569 +    }
  1.3570 +  }
  1.3571 +
  1.3572 +  if (is_illegal) {
  1.3573 +    ResourceMark rm(THREAD);
  1.3574 +    Exceptions::fthrow(
  1.3575 +      THREAD_AND_LOCATION,
  1.3576 +      vmSymbolHandles::java_lang_ClassFormatError(),
  1.3577 +      "Method %s in class %s has illegal modifiers: 0x%X",
  1.3578 +      name->as_C_string(), _class_name->as_C_string(), flags);
  1.3579 +    return;
  1.3580 +  }
  1.3581 +}
  1.3582 +
  1.3583 +void ClassFileParser::verify_legal_utf8(const unsigned char* buffer, int length, TRAPS) {
  1.3584 +  assert(_need_verify, "only called when _need_verify is true");
  1.3585 +  int i = 0;
  1.3586 +  int count = length >> 2;
  1.3587 +  for (int k=0; k<count; k++) {
  1.3588 +    unsigned char b0 = buffer[i];
  1.3589 +    unsigned char b1 = buffer[i+1];
  1.3590 +    unsigned char b2 = buffer[i+2];
  1.3591 +    unsigned char b3 = buffer[i+3];
  1.3592 +    // For an unsigned char v,
  1.3593 +    // (v | v - 1) is < 128 (highest bit 0) for 0 < v < 128;
  1.3594 +    // (v | v - 1) is >= 128 (highest bit 1) for v == 0 or v >= 128.
  1.3595 +    unsigned char res = b0 | b0 - 1 |
  1.3596 +                        b1 | b1 - 1 |
  1.3597 +                        b2 | b2 - 1 |
  1.3598 +                        b3 | b3 - 1;
  1.3599 +    if (res >= 128) break;
  1.3600 +    i += 4;
  1.3601 +  }
  1.3602 +  for(; i < length; i++) {
  1.3603 +    unsigned short c;
  1.3604 +    // no embedded zeros
  1.3605 +    guarantee_property((buffer[i] != 0), "Illegal UTF8 string in constant pool in class file %s", CHECK);
  1.3606 +    if(buffer[i] < 128) {
  1.3607 +      continue;
  1.3608 +    }
  1.3609 +    if ((i + 5) < length) { // see if it's legal supplementary character
  1.3610 +      if (UTF8::is_supplementary_character(&buffer[i])) {
  1.3611 +        c = UTF8::get_supplementary_character(&buffer[i]);
  1.3612 +        i += 5;
  1.3613 +        continue;
  1.3614 +      }
  1.3615 +    }
  1.3616 +    switch (buffer[i] >> 4) {
  1.3617 +      default: break;
  1.3618 +      case 0x8: case 0x9: case 0xA: case 0xB: case 0xF:
  1.3619 +        classfile_parse_error("Illegal UTF8 string in constant pool in class file %s", CHECK);
  1.3620 +      case 0xC: case 0xD:  // 110xxxxx  10xxxxxx
  1.3621 +        c = (buffer[i] & 0x1F) << 6;
  1.3622 +        i++;
  1.3623 +        if ((i < length) && ((buffer[i] & 0xC0) == 0x80)) {
  1.3624 +          c += buffer[i] & 0x3F;
  1.3625 +          if (_major_version <= 47 || c == 0 || c >= 0x80) {
  1.3626 +            // for classes with major > 47, c must a null or a character in its shortest form
  1.3627 +            break;
  1.3628 +          }
  1.3629 +        }
  1.3630 +        classfile_parse_error("Illegal UTF8 string in constant pool in class file %s", CHECK);
  1.3631 +      case 0xE:  // 1110xxxx 10xxxxxx 10xxxxxx
  1.3632 +        c = (buffer[i] & 0xF) << 12;
  1.3633 +        i += 2;
  1.3634 +        if ((i < length) && ((buffer[i-1] & 0xC0) == 0x80) && ((buffer[i] & 0xC0) == 0x80)) {
  1.3635 +          c += ((buffer[i-1] & 0x3F) << 6) + (buffer[i] & 0x3F);
  1.3636 +          if (_major_version <= 47 || c >= 0x800) {
  1.3637 +            // for classes with major > 47, c must be in its shortest form
  1.3638 +            break;
  1.3639 +          }
  1.3640 +        }
  1.3641 +        classfile_parse_error("Illegal UTF8 string in constant pool in class file %s", CHECK);
  1.3642 +    }  // end of switch
  1.3643 +  } // end of for
  1.3644 +}
  1.3645 +
  1.3646 +// Checks if name is a legal class name.
  1.3647 +void ClassFileParser::verify_legal_class_name(symbolHandle name, TRAPS) {
  1.3648 +  if (!_need_verify || _relax_verify) { return; }
  1.3649 +
  1.3650 +  char buf[fixed_buffer_size];
  1.3651 +  char* bytes = name->as_utf8_flexible_buffer(THREAD, buf, fixed_buffer_size);
  1.3652 +  unsigned int length = name->utf8_length();
  1.3653 +  bool legal = false;
  1.3654 +
  1.3655 +  if (length > 0) {
  1.3656 +    char* p;
  1.3657 +    if (bytes[0] == JVM_SIGNATURE_ARRAY) {
  1.3658 +      p = skip_over_field_signature(bytes, false, length, CHECK);
  1.3659 +      legal = (p != NULL) && ((p - bytes) == (int)length);
  1.3660 +    } else if (_major_version < JAVA_1_5_VERSION) {
  1.3661 +      if (bytes[0] != '<') {
  1.3662 +        p = skip_over_field_name(bytes, true, length);
  1.3663 +        legal = (p != NULL) && ((p - bytes) == (int)length);
  1.3664 +      }
  1.3665 +    } else {
  1.3666 +      // 4900761: relax the constraints based on JSR202 spec
  1.3667 +      // Class names may be drawn from the entire Unicode character set.
  1.3668 +      // Identifiers between '/' must be unqualified names.
  1.3669 +      // The utf8 string has been verified when parsing cpool entries.
  1.3670 +      legal = verify_unqualified_name(bytes, length, LegalClass);
  1.3671 +    }
  1.3672 +  }
  1.3673 +  if (!legal) {
  1.3674 +    ResourceMark rm(THREAD);
  1.3675 +    Exceptions::fthrow(
  1.3676 +      THREAD_AND_LOCATION,
  1.3677 +      vmSymbolHandles::java_lang_ClassFormatError(),
  1.3678 +      "Illegal class name \"%s\" in class file %s", bytes,
  1.3679 +      _class_name->as_C_string()
  1.3680 +    );
  1.3681 +    return;
  1.3682 +  }
  1.3683 +}
  1.3684 +
  1.3685 +// Checks if name is a legal field name.
  1.3686 +void ClassFileParser::verify_legal_field_name(symbolHandle name, TRAPS) {
  1.3687 +  if (!_need_verify || _relax_verify) { return; }
  1.3688 +
  1.3689 +  char buf[fixed_buffer_size];
  1.3690 +  char* bytes = name->as_utf8_flexible_buffer(THREAD, buf, fixed_buffer_size);
  1.3691 +  unsigned int length = name->utf8_length();
  1.3692 +  bool legal = false;
  1.3693 +
  1.3694 +  if (length > 0) {
  1.3695 +    if (_major_version < JAVA_1_5_VERSION) {
  1.3696 +      if (bytes[0] != '<') {
  1.3697 +        char* p = skip_over_field_name(bytes, false, length);
  1.3698 +        legal = (p != NULL) && ((p - bytes) == (int)length);
  1.3699 +      }
  1.3700 +    } else {
  1.3701 +      // 4881221: relax the constraints based on JSR202 spec
  1.3702 +      legal = verify_unqualified_name(bytes, length, LegalField);
  1.3703 +    }
  1.3704 +  }
  1.3705 +
  1.3706 +  if (!legal) {
  1.3707 +    ResourceMark rm(THREAD);
  1.3708 +    Exceptions::fthrow(
  1.3709 +      THREAD_AND_LOCATION,
  1.3710 +      vmSymbolHandles::java_lang_ClassFormatError(),
  1.3711 +      "Illegal field name \"%s\" in class %s", bytes,
  1.3712 +      _class_name->as_C_string()
  1.3713 +    );
  1.3714 +    return;
  1.3715 +  }
  1.3716 +}
  1.3717 +
  1.3718 +// Checks if name is a legal method name.
  1.3719 +void ClassFileParser::verify_legal_method_name(symbolHandle name, TRAPS) {
  1.3720 +  if (!_need_verify || _relax_verify) { return; }
  1.3721 +
  1.3722 +  assert(!name.is_null(), "method name is null");
  1.3723 +  char buf[fixed_buffer_size];
  1.3724 +  char* bytes = name->as_utf8_flexible_buffer(THREAD, buf, fixed_buffer_size);
  1.3725 +  unsigned int length = name->utf8_length();
  1.3726 +  bool legal = false;
  1.3727 +
  1.3728 +  if (length > 0) {
  1.3729 +    if (bytes[0] == '<') {
  1.3730 +      if (name == vmSymbols::object_initializer_name() || name == vmSymbols::class_initializer_name()) {
  1.3731 +        legal = true;
  1.3732 +      }
  1.3733 +    } else if (_major_version < JAVA_1_5_VERSION) {
  1.3734 +      char* p;
  1.3735 +      p = skip_over_field_name(bytes, false, length);
  1.3736 +      legal = (p != NULL) && ((p - bytes) == (int)length);
  1.3737 +    } else {
  1.3738 +      // 4881221: relax the constraints based on JSR202 spec
  1.3739 +      legal = verify_unqualified_name(bytes, length, LegalMethod);
  1.3740 +    }
  1.3741 +  }
  1.3742 +
  1.3743 +  if (!legal) {
  1.3744 +    ResourceMark rm(THREAD);
  1.3745 +    Exceptions::fthrow(
  1.3746 +      THREAD_AND_LOCATION,
  1.3747 +      vmSymbolHandles::java_lang_ClassFormatError(),
  1.3748 +      "Illegal method name \"%s\" in class %s", bytes,
  1.3749 +      _class_name->as_C_string()
  1.3750 +    );
  1.3751 +    return;
  1.3752 +  }
  1.3753 +}
  1.3754 +
  1.3755 +
  1.3756 +// Checks if signature is a legal field signature.
  1.3757 +void ClassFileParser::verify_legal_field_signature(symbolHandle name, symbolHandle signature, TRAPS) {
  1.3758 +  if (!_need_verify) { return; }
  1.3759 +
  1.3760 +  char buf[fixed_buffer_size];
  1.3761 +  char* bytes = signature->as_utf8_flexible_buffer(THREAD, buf, fixed_buffer_size);
  1.3762 +  unsigned int length = signature->utf8_length();
  1.3763 +  char* p = skip_over_field_signature(bytes, false, length, CHECK);
  1.3764 +
  1.3765 +  if (p == NULL || (p - bytes) != (int)length) {
  1.3766 +    ResourceMark rm(THREAD);
  1.3767 +    Exceptions::fthrow(
  1.3768 +      THREAD_AND_LOCATION,
  1.3769 +      vmSymbolHandles::java_lang_ClassFormatError(),
  1.3770 +      "Field \"%s\" in class %s has illegal signature \"%s\"",
  1.3771 +      name->as_C_string(), _class_name->as_C_string(), bytes
  1.3772 +    );
  1.3773 +    return;
  1.3774 +  }
  1.3775 +}
  1.3776 +
  1.3777 +// Checks if signature is a legal method signature.
  1.3778 +// Returns number of parameters
  1.3779 +int ClassFileParser::verify_legal_method_signature(symbolHandle name, symbolHandle signature, TRAPS) {
  1.3780 +  if (!_need_verify) {
  1.3781 +    // make sure caller's args_size will be less than 0 even for non-static
  1.3782 +    // method so it will be recomputed in compute_size_of_parameters().
  1.3783 +    return -2;
  1.3784 +  }
  1.3785 +
  1.3786 +  unsigned int args_size = 0;
  1.3787 +  char buf[fixed_buffer_size];
  1.3788 +  char* p = signature->as_utf8_flexible_buffer(THREAD, buf, fixed_buffer_size);
  1.3789 +  unsigned int length = signature->utf8_length();
  1.3790 +  char* nextp;
  1.3791 +
  1.3792 +  // The first character must be a '('
  1.3793 +  if ((length > 0) && (*p++ == JVM_SIGNATURE_FUNC)) {
  1.3794 +    length--;
  1.3795 +    // Skip over legal field signatures
  1.3796 +    nextp = skip_over_field_signature(p, false, length, CHECK_0);
  1.3797 +    while ((length > 0) && (nextp != NULL)) {
  1.3798 +      args_size++;
  1.3799 +      if (p[0] == 'J' || p[0] == 'D') {
  1.3800 +        args_size++;
  1.3801 +      }
  1.3802 +      length -= nextp - p;
  1.3803 +      p = nextp;
  1.3804 +      nextp = skip_over_field_signature(p, false, length, CHECK_0);
  1.3805 +    }
  1.3806 +    // The first non-signature thing better be a ')'
  1.3807 +    if ((length > 0) && (*p++ == JVM_SIGNATURE_ENDFUNC)) {
  1.3808 +      length--;
  1.3809 +      if (name->utf8_length() > 0 && name->byte_at(0) == '<') {
  1.3810 +        // All internal methods must return void
  1.3811 +        if ((length == 1) && (p[0] == JVM_SIGNATURE_VOID)) {
  1.3812 +          return args_size;
  1.3813 +        }
  1.3814 +      } else {
  1.3815 +        // Now we better just have a return value
  1.3816 +        nextp = skip_over_field_signature(p, true, length, CHECK_0);
  1.3817 +        if (nextp && ((int)length == (nextp - p))) {
  1.3818 +          return args_size;
  1.3819 +        }
  1.3820 +      }
  1.3821 +    }
  1.3822 +  }
  1.3823 +  // Report error
  1.3824 +  ResourceMark rm(THREAD);
  1.3825 +  Exceptions::fthrow(
  1.3826 +    THREAD_AND_LOCATION,
  1.3827 +    vmSymbolHandles::java_lang_ClassFormatError(),
  1.3828 +    "Method \"%s\" in class %s has illegal signature \"%s\"",
  1.3829 +    name->as_C_string(),  _class_name->as_C_string(), p
  1.3830 +  );
  1.3831 +  return 0;
  1.3832 +}
  1.3833 +
  1.3834 +
  1.3835 +// Unqualified names may not contain the characters '.', ';', or '/'.
  1.3836 +// Method names also may not contain the characters '<' or '>', unless <init> or <clinit>.
  1.3837 +// Note that method names may not be <init> or <clinit> in this method.
  1.3838 +// Because these names have been checked as special cases before calling this method
  1.3839 +// in verify_legal_method_name.
  1.3840 +bool ClassFileParser::verify_unqualified_name(char* name, unsigned int length, int type) {
  1.3841 +  jchar ch;
  1.3842 +
  1.3843 +  for (char* p = name; p != name + length; ) {
  1.3844 +    ch = *p;
  1.3845 +    if (ch < 128) {
  1.3846 +      p++;
  1.3847 +      if (ch == '.' || ch == ';') {
  1.3848 +        return false;   // do not permit '.' or ';'
  1.3849 +      }
  1.3850 +      if (type != LegalClass && ch == '/') {
  1.3851 +        return false;   // do not permit '/' unless it's class name
  1.3852 +      }
  1.3853 +      if (type == LegalMethod && (ch == '<' || ch == '>')) {
  1.3854 +        return false;   // do not permit '<' or '>' in method names
  1.3855 +      }
  1.3856 +    } else {
  1.3857 +      char* tmp_p = UTF8::next(p, &ch);
  1.3858 +      p = tmp_p;
  1.3859 +    }
  1.3860 +  }
  1.3861 +  return true;
  1.3862 +}
  1.3863 +
  1.3864 +
  1.3865 +// Take pointer to a string. Skip over the longest part of the string that could
  1.3866 +// be taken as a fieldname. Allow '/' if slash_ok is true.
  1.3867 +// Return a pointer to just past the fieldname.
  1.3868 +// Return NULL if no fieldname at all was found, or in the case of slash_ok
  1.3869 +// being true, we saw consecutive slashes (meaning we were looking for a
  1.3870 +// qualified path but found something that was badly-formed).
  1.3871 +char* ClassFileParser::skip_over_field_name(char* name, bool slash_ok, unsigned int length) {
  1.3872 +  char* p;
  1.3873 +  jchar ch;
  1.3874 +  jboolean last_is_slash = false;
  1.3875 +  jboolean not_first_ch = false;
  1.3876 +
  1.3877 +  for (p = name; p != name + length; not_first_ch = true) {
  1.3878 +    char* old_p = p;
  1.3879 +    ch = *p;
  1.3880 +    if (ch < 128) {
  1.3881 +      p++;
  1.3882 +      // quick check for ascii
  1.3883 +      if ((ch >= 'a' && ch <= 'z') ||
  1.3884 +          (ch >= 'A' && ch <= 'Z') ||
  1.3885 +          (ch == '_' || ch == '$') ||
  1.3886 +          (not_first_ch && ch >= '0' && ch <= '9')) {
  1.3887 +        last_is_slash = false;
  1.3888 +        continue;
  1.3889 +      }
  1.3890 +      if (slash_ok && ch == '/') {
  1.3891 +        if (last_is_slash) {
  1.3892 +          return NULL;  // Don't permit consecutive slashes
  1.3893 +        }
  1.3894 +        last_is_slash = true;
  1.3895 +        continue;
  1.3896 +      }
  1.3897 +    } else {
  1.3898 +      jint unicode_ch;
  1.3899 +      char* tmp_p = UTF8::next_character(p, &unicode_ch);
  1.3900 +      p = tmp_p;
  1.3901 +      last_is_slash = false;
  1.3902 +      // Check if ch is Java identifier start or is Java identifier part
  1.3903 +      // 4672820: call java.lang.Character methods directly without generating separate tables.
  1.3904 +      EXCEPTION_MARK;
  1.3905 +      instanceKlassHandle klass (THREAD, SystemDictionary::char_klass());
  1.3906 +
  1.3907 +      // return value
  1.3908 +      JavaValue result(T_BOOLEAN);
  1.3909 +      // Set up the arguments to isJavaIdentifierStart and isJavaIdentifierPart
  1.3910 +      JavaCallArguments args;
  1.3911 +      args.push_int(unicode_ch);
  1.3912 +
  1.3913 +      // public static boolean isJavaIdentifierStart(char ch);
  1.3914 +      JavaCalls::call_static(&result,
  1.3915 +                             klass,
  1.3916 +                             vmSymbolHandles::isJavaIdentifierStart_name(),
  1.3917 +                             vmSymbolHandles::int_bool_signature(),
  1.3918 +                             &args,
  1.3919 +                             THREAD);
  1.3920 +
  1.3921 +      if (HAS_PENDING_EXCEPTION) {
  1.3922 +        CLEAR_PENDING_EXCEPTION;
  1.3923 +        return 0;
  1.3924 +      }
  1.3925 +      if (result.get_jboolean()) {
  1.3926 +        continue;
  1.3927 +      }
  1.3928 +
  1.3929 +      if (not_first_ch) {
  1.3930 +        // public static boolean isJavaIdentifierPart(char ch);
  1.3931 +        JavaCalls::call_static(&result,
  1.3932 +                               klass,
  1.3933 +                               vmSymbolHandles::isJavaIdentifierPart_name(),
  1.3934 +                               vmSymbolHandles::int_bool_signature(),
  1.3935 +                               &args,
  1.3936 +                               THREAD);
  1.3937 +
  1.3938 +        if (HAS_PENDING_EXCEPTION) {
  1.3939 +          CLEAR_PENDING_EXCEPTION;
  1.3940 +          return 0;
  1.3941 +        }
  1.3942 +
  1.3943 +        if (result.get_jboolean()) {
  1.3944 +          continue;
  1.3945 +        }
  1.3946 +      }
  1.3947 +    }
  1.3948 +    return (not_first_ch) ? old_p : NULL;
  1.3949 +  }
  1.3950 +  return (not_first_ch) ? p : NULL;
  1.3951 +}
  1.3952 +
  1.3953 +
  1.3954 +// Take pointer to a string. Skip over the longest part of the string that could
  1.3955 +// be taken as a field signature. Allow "void" if void_ok.
  1.3956 +// Return a pointer to just past the signature.
  1.3957 +// Return NULL if no legal signature is found.
  1.3958 +char* ClassFileParser::skip_over_field_signature(char* signature,
  1.3959 +                                                 bool void_ok,
  1.3960 +                                                 unsigned int length,
  1.3961 +                                                 TRAPS) {
  1.3962 +  unsigned int array_dim = 0;
  1.3963 +  while (length > 0) {
  1.3964 +    switch (signature[0]) {
  1.3965 +      case JVM_SIGNATURE_VOID: if (!void_ok) { return NULL; }
  1.3966 +      case JVM_SIGNATURE_BOOLEAN:
  1.3967 +      case JVM_SIGNATURE_BYTE:
  1.3968 +      case JVM_SIGNATURE_CHAR:
  1.3969 +      case JVM_SIGNATURE_SHORT:
  1.3970 +      case JVM_SIGNATURE_INT:
  1.3971 +      case JVM_SIGNATURE_FLOAT:
  1.3972 +      case JVM_SIGNATURE_LONG:
  1.3973 +      case JVM_SIGNATURE_DOUBLE:
  1.3974 +        return signature + 1;
  1.3975 +      case JVM_SIGNATURE_CLASS: {
  1.3976 +        if (_major_version < JAVA_1_5_VERSION) {
  1.3977 +          // Skip over the class name if one is there
  1.3978 +          char* p = skip_over_field_name(signature + 1, true, --length);
  1.3979 +
  1.3980 +          // The next character better be a semicolon
  1.3981 +          if (p && (p - signature) > 1 && p[0] == ';') {
  1.3982 +            return p + 1;
  1.3983 +          }
  1.3984 +        } else {
  1.3985 +          // 4900761: For class version > 48, any unicode is allowed in class name.
  1.3986 +          length--;
  1.3987 +          signature++;
  1.3988 +          while (length > 0 && signature[0] != ';') {
  1.3989 +            if (signature[0] == '.') {
  1.3990 +              classfile_parse_error("Class name contains illegal character '.' in descriptor in class file %s", CHECK_0);
  1.3991 +            }
  1.3992 +            length--;
  1.3993 +            signature++;
  1.3994 +          }
  1.3995 +          if (signature[0] == ';') { return signature + 1; }
  1.3996 +        }
  1.3997 +
  1.3998 +        return NULL;
  1.3999 +      }
  1.4000 +      case JVM_SIGNATURE_ARRAY:
  1.4001 +        array_dim++;
  1.4002 +        if (array_dim > 255) {
  1.4003 +          // 4277370: array descriptor is valid only if it represents 255 or fewer dimensions.
  1.4004 +          classfile_parse_error("Array type descriptor has more than 255 dimensions in class file %s", CHECK_0);
  1.4005 +        }
  1.4006 +        // The rest of what's there better be a legal signature
  1.4007 +        signature++;
  1.4008 +        length--;
  1.4009 +        void_ok = false;
  1.4010 +        break;
  1.4011 +
  1.4012 +      default:
  1.4013 +        return NULL;
  1.4014 +    }
  1.4015 +  }
  1.4016 +  return NULL;
  1.4017 +}

mercurial