annotate src/share/vm/classfile/classFileParser.cpp @ 2945:5b58979183f9

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