src/share/vm/interpreter/rewriter.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8161987 Sdiff src/share/vm/interpreter

src/share/vm/interpreter/rewriter.cpp

Print this page
rev 8156 : 8157181: Compilers accept modification of final fields outside initializer methods
Summary: Track initialized final field updates; disable constant folding if an update is detected.
Reviewed-by: vlivanov, dnsimon, forax, never, kvn, coleenp


 379             bc.number_of_pairs() < BinarySwitchThreshold
 380             ? Bytecodes::_fast_linearswitch
 381             : Bytecodes::_fast_binaryswitch
 382           );
 383 #endif
 384           break;
 385         }
 386         case Bytecodes::_fast_linearswitch:
 387         case Bytecodes::_fast_binaryswitch: {
 388 #ifndef CC_INTERP
 389           (*bcp) = Bytecodes::_lookupswitch;
 390 #endif
 391           break;
 392         }
 393 
 394         case Bytecodes::_invokespecial  : {
 395           rewrite_invokespecial(bcp, prefix_length+1, reverse, invokespecial_error);
 396           break;
 397         }
 398 





































 399         case Bytecodes::_getstatic      : // fall through
 400         case Bytecodes::_putstatic      : // fall through
 401         case Bytecodes::_getfield       : // fall through
 402         case Bytecodes::_putfield       : // fall through
 403         case Bytecodes::_invokevirtual  : // fall through
 404         case Bytecodes::_invokestatic   :
 405         case Bytecodes::_invokeinterface:
 406         case Bytecodes::_invokehandle   : // if reverse=true
 407           rewrite_member_reference(bcp, prefix_length+1, reverse);
 408           break;
 409         case Bytecodes::_invokedynamic:
 410           rewrite_invokedynamic(bcp, prefix_length+1, reverse);
 411           break;
 412         case Bytecodes::_ldc:
 413         case Bytecodes::_fast_aldc:  // if reverse=true
 414           maybe_rewrite_ldc(bcp, prefix_length+1, false, reverse);
 415           break;
 416         case Bytecodes::_ldc_w:
 417         case Bytecodes::_fast_aldc_w:  // if reverse=true
 418           maybe_rewrite_ldc(bcp, prefix_length+1, true, reverse);
 419           break;
 420         case Bytecodes::_jsr            : // fall through
 421         case Bytecodes::_jsr_w          : nof_jsrs++;                   break;
 422         case Bytecodes::_monitorenter   : // fall through




 379             bc.number_of_pairs() < BinarySwitchThreshold
 380             ? Bytecodes::_fast_linearswitch
 381             : Bytecodes::_fast_binaryswitch
 382           );
 383 #endif
 384           break;
 385         }
 386         case Bytecodes::_fast_linearswitch:
 387         case Bytecodes::_fast_binaryswitch: {
 388 #ifndef CC_INTERP
 389           (*bcp) = Bytecodes::_lookupswitch;
 390 #endif
 391           break;
 392         }
 393 
 394         case Bytecodes::_invokespecial  : {
 395           rewrite_invokespecial(bcp, prefix_length+1, reverse, invokespecial_error);
 396           break;
 397         }
 398 
 399         case Bytecodes::_putstatic      :
 400         case Bytecodes::_putfield       : {
 401           if (!reverse) {
 402             // Check if any final field of the class given as parameter is modified
 403             // outside of initializer methods of the class. Fields that are modified
 404             // are marked with a flag. For marked fields, the compilers do not perform
 405             // constant folding (as the field can be changed after initialization).
 406             //
 407             // The check is performed after verification and only if verification has
 408             // succeeded. Therefore, the class is guaranteed to be well-formed.
 409             InstanceKlass* klass = method->method_holder();
 410             u2 bc_index = Bytes::get_Java_u2(bcp + prefix_length + 1);
 411             constantPoolHandle cp(method->constants());
 412             Symbol* field_name = cp->name_ref_at(bc_index);
 413             Symbol* field_sig = cp->signature_ref_at(bc_index);
 414             Symbol* ref_class_name = cp->klass_name_at(cp->klass_ref_index_at(bc_index));
 415 
 416             if (klass->name() == ref_class_name) {
 417               fieldDescriptor fd;
 418               klass->find_field(field_name, field_sig, &fd);
 419               if (fd.access_flags().is_final()) {
 420                 if (fd.access_flags().is_static()) {
 421                   assert(c == Bytecodes::_putstatic, "must be putstatic");
 422                   if (!method->is_static_initializer()) {
 423                     fd.set_has_initialized_final_update(true);
 424                   }
 425                 } else {
 426                   assert(c == Bytecodes::_putfield, "must be putfield");
 427                   if (!method->is_object_initializer()) {
 428                     fd.set_has_initialized_final_update(true);
 429                   }
 430                 }
 431               }
 432             }
 433           }
 434         }
 435         // fall through
 436         case Bytecodes::_getstatic      : // fall through

 437         case Bytecodes::_getfield       : // fall through

 438         case Bytecodes::_invokevirtual  : // fall through
 439         case Bytecodes::_invokestatic   :
 440         case Bytecodes::_invokeinterface:
 441         case Bytecodes::_invokehandle   : // if reverse=true
 442           rewrite_member_reference(bcp, prefix_length+1, reverse);
 443           break;
 444         case Bytecodes::_invokedynamic:
 445           rewrite_invokedynamic(bcp, prefix_length+1, reverse);
 446           break;
 447         case Bytecodes::_ldc:
 448         case Bytecodes::_fast_aldc:  // if reverse=true
 449           maybe_rewrite_ldc(bcp, prefix_length+1, false, reverse);
 450           break;
 451         case Bytecodes::_ldc_w:
 452         case Bytecodes::_fast_aldc_w:  // if reverse=true
 453           maybe_rewrite_ldc(bcp, prefix_length+1, true, reverse);
 454           break;
 455         case Bytecodes::_jsr            : // fall through
 456         case Bytecodes::_jsr_w          : nof_jsrs++;                   break;
 457         case Bytecodes::_monitorenter   : // fall through


src/share/vm/interpreter/rewriter.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File