hotspot/src/share/vm/interpreter/rewriter.cpp
changeset 46783 bfa353c0d440
parent 46741 d5a7407108b4
child 47103 a993ec29ec75
equal deleted inserted replaced
46778:f504c6f2eea5 46783:bfa353c0d440
   353 // Rewrites a method given the index_map information
   353 // Rewrites a method given the index_map information
   354 void Rewriter::scan_method(Method* method, bool reverse, bool* invokespecial_error) {
   354 void Rewriter::scan_method(Method* method, bool reverse, bool* invokespecial_error) {
   355 
   355 
   356   int nof_jsrs = 0;
   356   int nof_jsrs = 0;
   357   bool has_monitor_bytecodes = false;
   357   bool has_monitor_bytecodes = false;
   358 
   358   Bytecodes::Code c;
   359   {
   359 
   360     // We cannot tolerate a GC in this block, because we've
   360   // Bytecodes and their length
   361     // cached the bytecodes in 'code_base'. If the Method*
   361   const address code_base = method->code_base();
   362     // moves, the bytecodes will also move.
   362   const int code_length = method->code_size();
   363     NoSafepointVerifier nsv;
   363 
   364     Bytecodes::Code c;
   364   int bc_length;
   365 
   365   for (int bci = 0; bci < code_length; bci += bc_length) {
   366     // Bytecodes and their length
   366     address bcp = code_base + bci;
   367     const address code_base = method->code_base();
   367     int prefix_length = 0;
   368     const int code_length = method->code_size();
   368     c = (Bytecodes::Code)(*bcp);
   369 
   369 
   370     int bc_length;
   370     // Since we have the code, see if we can get the length
   371     for (int bci = 0; bci < code_length; bci += bc_length) {
   371     // directly. Some more complicated bytecodes will report
   372       address bcp = code_base + bci;
   372     // a length of zero, meaning we need to make another method
   373       int prefix_length = 0;
   373     // call to calculate the length.
   374       c = (Bytecodes::Code)(*bcp);
   374     bc_length = Bytecodes::length_for(c);
   375 
   375     if (bc_length == 0) {
   376       // Since we have the code, see if we can get the length
   376       bc_length = Bytecodes::length_at(method, bcp);
   377       // directly. Some more complicated bytecodes will report
   377 
   378       // a length of zero, meaning we need to make another method
   378       // length_at will put us at the bytecode after the one modified
   379       // call to calculate the length.
   379       // by 'wide'. We don't currently examine any of the bytecodes
   380       bc_length = Bytecodes::length_for(c);
   380       // modified by wide, but in case we do in the future...
   381       if (bc_length == 0) {
   381       if (c == Bytecodes::_wide) {
   382         bc_length = Bytecodes::length_at(method, bcp);
   382         prefix_length = 1;
   383 
   383         c = (Bytecodes::Code)bcp[1];
   384         // length_at will put us at the bytecode after the one modified
   384       }
   385         // by 'wide'. We don't currently examine any of the bytecodes
   385     }
   386         // modified by wide, but in case we do in the future...
   386 
   387         if (c == Bytecodes::_wide) {
   387     assert(bc_length != 0, "impossible bytecode length");
   388           prefix_length = 1;
   388 
   389           c = (Bytecodes::Code)bcp[1];
   389     switch (c) {
   390         }
   390       case Bytecodes::_lookupswitch   : {
   391       }
       
   392 
       
   393       assert(bc_length != 0, "impossible bytecode length");
       
   394 
       
   395       switch (c) {
       
   396         case Bytecodes::_lookupswitch   : {
       
   397 #ifndef CC_INTERP
   391 #ifndef CC_INTERP
   398           Bytecode_lookupswitch bc(method, bcp);
   392         Bytecode_lookupswitch bc(method, bcp);
   399           (*bcp) = (
   393         (*bcp) = (
   400             bc.number_of_pairs() < BinarySwitchThreshold
   394           bc.number_of_pairs() < BinarySwitchThreshold
   401             ? Bytecodes::_fast_linearswitch
   395           ? Bytecodes::_fast_linearswitch
   402             : Bytecodes::_fast_binaryswitch
   396           : Bytecodes::_fast_binaryswitch
   403           );
   397         );
   404 #endif
   398 #endif
   405           break;
   399         break;
   406         }
   400       }
   407         case Bytecodes::_fast_linearswitch:
   401       case Bytecodes::_fast_linearswitch:
   408         case Bytecodes::_fast_binaryswitch: {
   402       case Bytecodes::_fast_binaryswitch: {
   409 #ifndef CC_INTERP
   403 #ifndef CC_INTERP
   410           (*bcp) = Bytecodes::_lookupswitch;
   404         (*bcp) = Bytecodes::_lookupswitch;
   411 #endif
   405 #endif
   412           break;
   406         break;
   413         }
   407       }
   414 
   408 
   415         case Bytecodes::_invokespecial  : {
   409       case Bytecodes::_invokespecial  : {
   416           rewrite_invokespecial(bcp, prefix_length+1, reverse, invokespecial_error);
   410         rewrite_invokespecial(bcp, prefix_length+1, reverse, invokespecial_error);
   417           break;
   411         break;
   418         }
   412       }
   419 
   413 
   420         case Bytecodes::_putstatic      :
   414       case Bytecodes::_putstatic      :
   421         case Bytecodes::_putfield       : {
   415       case Bytecodes::_putfield       : {
   422           if (!reverse) {
   416         if (!reverse) {
   423             // Check if any final field of the class given as parameter is modified
   417           // Check if any final field of the class given as parameter is modified
   424             // outside of initializer methods of the class. Fields that are modified
   418           // outside of initializer methods of the class. Fields that are modified
   425             // are marked with a flag. For marked fields, the compilers do not perform
   419           // are marked with a flag. For marked fields, the compilers do not perform
   426             // constant folding (as the field can be changed after initialization).
   420           // constant folding (as the field can be changed after initialization).
   427             //
   421           //
   428             // The check is performed after verification and only if verification has
   422           // The check is performed after verification and only if verification has
   429             // succeeded. Therefore, the class is guaranteed to be well-formed.
   423           // succeeded. Therefore, the class is guaranteed to be well-formed.
   430             InstanceKlass* klass = method->method_holder();
   424           InstanceKlass* klass = method->method_holder();
   431             u2 bc_index = Bytes::get_Java_u2(bcp + prefix_length + 1);
   425           u2 bc_index = Bytes::get_Java_u2(bcp + prefix_length + 1);
   432             constantPoolHandle cp(method->constants());
   426           constantPoolHandle cp(method->constants());
   433             Symbol* ref_class_name = cp->klass_name_at(cp->klass_ref_index_at(bc_index));
   427           Symbol* ref_class_name = cp->klass_name_at(cp->klass_ref_index_at(bc_index));
   434 
   428 
   435             if (klass->name() == ref_class_name) {
   429           if (klass->name() == ref_class_name) {
   436               Symbol* field_name = cp->name_ref_at(bc_index);
   430             Symbol* field_name = cp->name_ref_at(bc_index);
   437               Symbol* field_sig = cp->signature_ref_at(bc_index);
   431             Symbol* field_sig = cp->signature_ref_at(bc_index);
   438 
   432 
   439               fieldDescriptor fd;
   433             fieldDescriptor fd;
   440               if (klass->find_field(field_name, field_sig, &fd) != NULL) {
   434             if (klass->find_field(field_name, field_sig, &fd) != NULL) {
   441                 if (fd.access_flags().is_final()) {
   435               if (fd.access_flags().is_final()) {
   442                   if (fd.access_flags().is_static()) {
   436                 if (fd.access_flags().is_static()) {
   443                     if (!method->is_static_initializer()) {
   437                   if (!method->is_static_initializer()) {
   444                       fd.set_has_initialized_final_update(true);
   438                     fd.set_has_initialized_final_update(true);
   445                     }
   439                   }
   446                   } else {
   440                 } else {
   447                     if (!method->is_object_initializer()) {
   441                   if (!method->is_object_initializer()) {
   448                       fd.set_has_initialized_final_update(true);
   442                     fd.set_has_initialized_final_update(true);
   449                     }
       
   450                   }
   443                   }
   451                 }
   444                 }
   452               }
   445               }
   453             }
   446             }
   454           }
   447           }
   455         }
   448         }
   456         // fall through
   449       }
   457         case Bytecodes::_getstatic      : // fall through
   450       // fall through
   458         case Bytecodes::_getfield       : // fall through
   451       case Bytecodes::_getstatic      : // fall through
   459         case Bytecodes::_invokevirtual  : // fall through
   452       case Bytecodes::_getfield       : // fall through
   460         case Bytecodes::_invokestatic   :
   453       case Bytecodes::_invokevirtual  : // fall through
   461         case Bytecodes::_invokeinterface:
   454       case Bytecodes::_invokestatic   :
   462         case Bytecodes::_invokehandle   : // if reverse=true
   455       case Bytecodes::_invokeinterface:
   463           rewrite_member_reference(bcp, prefix_length+1, reverse);
   456       case Bytecodes::_invokehandle   : // if reverse=true
   464           break;
   457         rewrite_member_reference(bcp, prefix_length+1, reverse);
   465         case Bytecodes::_invokedynamic:
   458         break;
   466           rewrite_invokedynamic(bcp, prefix_length+1, reverse);
   459       case Bytecodes::_invokedynamic:
   467           break;
   460         rewrite_invokedynamic(bcp, prefix_length+1, reverse);
   468         case Bytecodes::_ldc:
   461         break;
   469         case Bytecodes::_fast_aldc:  // if reverse=true
   462       case Bytecodes::_ldc:
   470           maybe_rewrite_ldc(bcp, prefix_length+1, false, reverse);
   463       case Bytecodes::_fast_aldc:  // if reverse=true
   471           break;
   464         maybe_rewrite_ldc(bcp, prefix_length+1, false, reverse);
   472         case Bytecodes::_ldc_w:
   465         break;
   473         case Bytecodes::_fast_aldc_w:  // if reverse=true
   466       case Bytecodes::_ldc_w:
   474           maybe_rewrite_ldc(bcp, prefix_length+1, true, reverse);
   467       case Bytecodes::_fast_aldc_w:  // if reverse=true
   475           break;
   468         maybe_rewrite_ldc(bcp, prefix_length+1, true, reverse);
   476         case Bytecodes::_jsr            : // fall through
   469         break;
   477         case Bytecodes::_jsr_w          : nof_jsrs++;                   break;
   470       case Bytecodes::_jsr            : // fall through
   478         case Bytecodes::_monitorenter   : // fall through
   471       case Bytecodes::_jsr_w          : nof_jsrs++;                   break;
   479         case Bytecodes::_monitorexit    : has_monitor_bytecodes = true; break;
   472       case Bytecodes::_monitorenter   : // fall through
   480 
   473       case Bytecodes::_monitorexit    : has_monitor_bytecodes = true; break;
   481         default: break;
   474 
   482       }
   475       default: break;
   483     }
   476     }
   484   }
   477   }
   485 
   478 
   486   // Update access flags
   479   // Update access flags
   487   if (has_monitor_bytecodes) {
   480   if (has_monitor_bytecodes) {