hotspot/src/share/vm/interpreter/interpreterRuntime.cpp
changeset 30132 1f788eb36811
parent 30117 cce2cdac56dc
child 30599 a8ade6f048fe
equal deleted inserted replaced
30130:386d3e9878bc 30132:1f788eb36811
   535 
   535 
   536 //------------------------------------------------------------------------------------------------------------------------
   536 //------------------------------------------------------------------------------------------------------------------------
   537 // Fields
   537 // Fields
   538 //
   538 //
   539 
   539 
   540 IRT_ENTRY(void, InterpreterRuntime::resolve_get_put(JavaThread* thread, Bytecodes::Code bytecode))
   540 void InterpreterRuntime::resolve_get_put(JavaThread* thread, Bytecodes::Code bytecode) {
       
   541   Thread* THREAD = thread;
   541   // resolve field
   542   // resolve field
   542   fieldDescriptor info;
   543   fieldDescriptor info;
   543   constantPoolHandle pool(thread, method(thread)->constants());
   544   constantPoolHandle pool(thread, method(thread)->constants());
   544   bool is_put    = (bytecode == Bytecodes::_putfield  || bytecode == Bytecodes::_nofast_putfield ||
   545   bool is_put    = (bytecode == Bytecodes::_putfield  || bytecode == Bytecodes::_nofast_putfield ||
   545                     bytecode == Bytecodes::_putstatic);
   546                     bytecode == Bytecodes::_putstatic);
   550     LinkResolver::resolve_field_access(info, pool, get_index_u2_cpcache(thread, bytecode),
   551     LinkResolver::resolve_field_access(info, pool, get_index_u2_cpcache(thread, bytecode),
   551                                        bytecode, CHECK);
   552                                        bytecode, CHECK);
   552   } // end JvmtiHideSingleStepping
   553   } // end JvmtiHideSingleStepping
   553 
   554 
   554   // check if link resolution caused cpCache to be updated
   555   // check if link resolution caused cpCache to be updated
   555   if (already_resolved(thread)) return;
   556   ConstantPoolCacheEntry* cp_cache_entry = cache_entry(thread);
       
   557   if (cp_cache_entry->is_resolved(bytecode)) return;
   556 
   558 
   557   // compute auxiliary field attributes
   559   // compute auxiliary field attributes
   558   TosState state  = as_TosState(info.field_type());
   560   TosState state  = as_TosState(info.field_type());
   559 
   561 
   560   // We need to delay resolving put instructions on final fields
   562   // We need to delay resolving put instructions on final fields
   578     if (is_put || !info.access_flags().is_final()) {
   580     if (is_put || !info.access_flags().is_final()) {
   579       put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
   581       put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
   580     }
   582     }
   581   }
   583   }
   582 
   584 
   583   cache_entry(thread)->set_field(
   585   cp_cache_entry->set_field(
   584     get_code,
   586     get_code,
   585     put_code,
   587     put_code,
   586     info.field_holder(),
   588     info.field_holder(),
   587     info.index(),
   589     info.index(),
   588     info.offset(),
   590     info.offset(),
   589     state,
   591     state,
   590     info.access_flags().is_final(),
   592     info.access_flags().is_final(),
   591     info.access_flags().is_volatile(),
   593     info.access_flags().is_volatile(),
   592     pool->pool_holder()
   594     pool->pool_holder()
   593   );
   595   );
   594 IRT_END
   596 }
   595 
   597 
   596 
   598 
   597 //------------------------------------------------------------------------------------------------------------------------
   599 //------------------------------------------------------------------------------------------------------------------------
   598 // Synchronization
   600 // Synchronization
   599 //
   601 //
   684 
   686 
   685 IRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* thread, Method* method, address bcp))
   687 IRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* thread, Method* method, address bcp))
   686   JvmtiExport::post_raw_breakpoint(thread, method, bcp);
   688   JvmtiExport::post_raw_breakpoint(thread, method, bcp);
   687 IRT_END
   689 IRT_END
   688 
   690 
   689 IRT_ENTRY(void, InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode)) {
   691 void InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode) {
       
   692   Thread* THREAD = thread;
   690   // extract receiver from the outgoing argument list if necessary
   693   // extract receiver from the outgoing argument list if necessary
   691   Handle receiver(thread, NULL);
   694   Handle receiver(thread, NULL);
   692   if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface) {
   695   if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface) {
   693     ResourceMark rm(thread);
   696     ResourceMark rm(thread);
   694     methodHandle m (thread, method(thread));
   697     methodHandle m (thread, method(thread));
   708   constantPoolHandle pool(thread, method(thread)->constants());
   711   constantPoolHandle pool(thread, method(thread)->constants());
   709 
   712 
   710   {
   713   {
   711     JvmtiHideSingleStepping jhss(thread);
   714     JvmtiHideSingleStepping jhss(thread);
   712     LinkResolver::resolve_invoke(info, receiver, pool,
   715     LinkResolver::resolve_invoke(info, receiver, pool,
   713                                  get_index_u2_cpcache(thread, bytecode), bytecode, CHECK);
   716                                  get_index_u2_cpcache(thread, bytecode), bytecode,
       
   717                                  CHECK);
   714     if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
   718     if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
   715       int retry_count = 0;
   719       int retry_count = 0;
   716       while (info.resolved_method()->is_old()) {
   720       while (info.resolved_method()->is_old()) {
   717         // It is very unlikely that method is redefined more than 100 times
   721         // It is very unlikely that method is redefined more than 100 times
   718         // in the middle of resolve. If it is looping here more than 100 times
   722         // in the middle of resolve. If it is looping here more than 100 times
   719         // means then there could be a bug here.
   723         // means then there could be a bug here.
   720         guarantee((retry_count++ < 100),
   724         guarantee((retry_count++ < 100),
   721                   "Could not resolve to latest version of redefined method");
   725                   "Could not resolve to latest version of redefined method");
   722         // method is redefined in the middle of resolve so re-try.
   726         // method is redefined in the middle of resolve so re-try.
   723         LinkResolver::resolve_invoke(info, receiver, pool,
   727         LinkResolver::resolve_invoke(info, receiver, pool,
   724                                      get_index_u2_cpcache(thread, bytecode), bytecode, CHECK);
   728                                      get_index_u2_cpcache(thread, bytecode), bytecode,
       
   729                                      CHECK);
   725       }
   730       }
   726     }
   731     }
   727   } // end JvmtiHideSingleStepping
   732   } // end JvmtiHideSingleStepping
   728 
   733 
   729   // check if link resolution caused cpCache to be updated
   734   // check if link resolution caused cpCache to be updated
   730   if (already_resolved(thread)) return;
   735   ConstantPoolCacheEntry* cp_cache_entry = cache_entry(thread);
       
   736   if (cp_cache_entry->is_resolved(bytecode)) return;
   731 
   737 
   732   if (bytecode == Bytecodes::_invokeinterface) {
   738   if (bytecode == Bytecodes::_invokeinterface) {
   733     if (TraceItables && Verbose) {
   739     if (TraceItables && Verbose) {
   734       ResourceMark rm(thread);
   740       ResourceMark rm(thread);
   735       tty->print_cr("Resolving: klass: %s to method: %s", info.resolved_klass()->name()->as_C_string(), info.resolved_method()->name()->as_C_string());
   741       tty->print_cr("Resolving: klass: %s to method: %s", info.resolved_klass()->name()->as_C_string(), info.resolved_method()->name()->as_C_string());
   760            info.call_kind() == CallInfo::vtable_call, "");
   766            info.call_kind() == CallInfo::vtable_call, "");
   761   }
   767   }
   762 #endif
   768 #endif
   763   switch (info.call_kind()) {
   769   switch (info.call_kind()) {
   764   case CallInfo::direct_call:
   770   case CallInfo::direct_call:
   765     cache_entry(thread)->set_direct_call(
   771     cp_cache_entry->set_direct_call(
   766       bytecode,
   772       bytecode,
   767       info.resolved_method());
   773       info.resolved_method());
   768     break;
   774     break;
   769   case CallInfo::vtable_call:
   775   case CallInfo::vtable_call:
   770     cache_entry(thread)->set_vtable_call(
   776     cp_cache_entry->set_vtable_call(
   771       bytecode,
   777       bytecode,
   772       info.resolved_method(),
   778       info.resolved_method(),
   773       info.vtable_index());
   779       info.vtable_index());
   774     break;
   780     break;
   775   case CallInfo::itable_call:
   781   case CallInfo::itable_call:
   776     cache_entry(thread)->set_itable_call(
   782     cp_cache_entry->set_itable_call(
   777       bytecode,
   783       bytecode,
   778       info.resolved_method(),
   784       info.resolved_method(),
   779       info.itable_index());
   785       info.itable_index());
   780     break;
   786     break;
   781   default:  ShouldNotReachHere();
   787   default:  ShouldNotReachHere();
   782   }
   788   }
   783 }
   789 }
   784 IRT_END
       
   785 
   790 
   786 
   791 
   787 // First time execution:  Resolve symbols, create a permanent MethodType object.
   792 // First time execution:  Resolve symbols, create a permanent MethodType object.
   788 IRT_ENTRY(void, InterpreterRuntime::resolve_invokehandle(JavaThread* thread)) {
   793 void InterpreterRuntime::resolve_invokehandle(JavaThread* thread) {
       
   794   Thread* THREAD = thread;
   789   const Bytecodes::Code bytecode = Bytecodes::_invokehandle;
   795   const Bytecodes::Code bytecode = Bytecodes::_invokehandle;
   790 
   796 
   791   // resolve method
   797   // resolve method
   792   CallInfo info;
   798   CallInfo info;
   793   constantPoolHandle pool(thread, method(thread)->constants());
   799   constantPoolHandle pool(thread, method(thread)->constants());
   794 
       
   795   {
   800   {
   796     JvmtiHideSingleStepping jhss(thread);
   801     JvmtiHideSingleStepping jhss(thread);
   797     LinkResolver::resolve_invoke(info, Handle(), pool,
   802     LinkResolver::resolve_invoke(info, Handle(), pool,
   798                                  get_index_u2_cpcache(thread, bytecode), bytecode, CHECK);
   803                                  get_index_u2_cpcache(thread, bytecode), bytecode,
       
   804                                  CHECK);
   799   } // end JvmtiHideSingleStepping
   805   } // end JvmtiHideSingleStepping
   800 
   806 
   801   cache_entry(thread)->set_method_handle(pool, info);
   807   ConstantPoolCacheEntry* cp_cache_entry = cache_entry(thread);
   802 }
   808   cp_cache_entry->set_method_handle(pool, info);
   803 IRT_END
   809 }
   804 
       
   805 
   810 
   806 // First time execution:  Resolve symbols, create a permanent CallSite object.
   811 // First time execution:  Resolve symbols, create a permanent CallSite object.
   807 IRT_ENTRY(void, InterpreterRuntime::resolve_invokedynamic(JavaThread* thread)) {
   812 void InterpreterRuntime::resolve_invokedynamic(JavaThread* thread) {
       
   813   Thread* THREAD = thread;
   808   const Bytecodes::Code bytecode = Bytecodes::_invokedynamic;
   814   const Bytecodes::Code bytecode = Bytecodes::_invokedynamic;
   809 
   815 
   810   //TO DO: consider passing BCI to Java.
   816   //TO DO: consider passing BCI to Java.
   811   //  int caller_bci = method(thread)->bci_from(bcp(thread));
   817   //  int caller_bci = method(thread)->bci_from(bcp(thread));
   812 
   818 
   821   } // end JvmtiHideSingleStepping
   827   } // end JvmtiHideSingleStepping
   822 
   828 
   823   ConstantPoolCacheEntry* cp_cache_entry = pool->invokedynamic_cp_cache_entry_at(index);
   829   ConstantPoolCacheEntry* cp_cache_entry = pool->invokedynamic_cp_cache_entry_at(index);
   824   cp_cache_entry->set_dynamic_call(pool, info);
   830   cp_cache_entry->set_dynamic_call(pool, info);
   825 }
   831 }
   826 IRT_END
   832 
   827 
   833 // This function is the interface to the assembly code. It returns the resolved
       
   834 // cpCache entry.  This doesn't safepoint, but the helper routines safepoint.
       
   835 // This function will check for redefinition!
       
   836 IRT_ENTRY(void, InterpreterRuntime::resolve_from_cache(JavaThread* thread, Bytecodes::Code bytecode)) {
       
   837   switch (bytecode) {
       
   838   case Bytecodes::_getstatic:
       
   839   case Bytecodes::_putstatic:
       
   840   case Bytecodes::_getfield:
       
   841   case Bytecodes::_putfield:
       
   842     resolve_get_put(thread, bytecode);
       
   843     break;
       
   844   case Bytecodes::_invokevirtual:
       
   845   case Bytecodes::_invokespecial:
       
   846   case Bytecodes::_invokestatic:
       
   847   case Bytecodes::_invokeinterface:
       
   848     resolve_invoke(thread, bytecode);
       
   849     break;
       
   850   case Bytecodes::_invokehandle:
       
   851     resolve_invokehandle(thread);
       
   852     break;
       
   853   case Bytecodes::_invokedynamic:
       
   854     resolve_invokedynamic(thread);
       
   855     break;
       
   856   default:
       
   857     fatal(err_msg("unexpected bytecode: %s", Bytecodes::name(bytecode)));
       
   858     break;
       
   859   }
       
   860 }
       
   861 IRT_END
   828 
   862 
   829 //------------------------------------------------------------------------------------------------------------------------
   863 //------------------------------------------------------------------------------------------------------------------------
   830 // Miscellaneous
   864 // Miscellaneous
   831 
   865 
   832 
   866