< prev index next >

src/hotspot/share/interpreter/interpreterRuntime.cpp

Print this page

   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "jvm_io.h"
  27 #include "classfile/javaClasses.inline.hpp"
  28 #include "classfile/symbolTable.hpp"

  29 #include "classfile/vmClasses.hpp"
  30 #include "classfile/vmSymbols.hpp"
  31 #include "code/codeCache.hpp"
  32 #include "compiler/compilationPolicy.hpp"
  33 #include "compiler/compileBroker.hpp"
  34 #include "compiler/disassembler.hpp"
  35 #include "gc/shared/barrierSetNMethod.hpp"
  36 #include "gc/shared/collectedHeap.hpp"
  37 #include "interpreter/interpreter.hpp"
  38 #include "interpreter/interpreterRuntime.hpp"
  39 #include "interpreter/linkResolver.hpp"
  40 #include "interpreter/templateTable.hpp"
  41 #include "logging/log.hpp"
  42 #include "memory/oopFactory.hpp"
  43 #include "memory/resourceArea.hpp"
  44 #include "memory/universe.hpp"
  45 #include "oops/constantPool.hpp"
  46 #include "oops/cpCache.inline.hpp"



  47 #include "oops/instanceKlass.inline.hpp"
  48 #include "oops/klass.inline.hpp"
  49 #include "oops/methodData.hpp"
  50 #include "oops/objArrayKlass.hpp"
  51 #include "oops/objArrayOop.inline.hpp"
  52 #include "oops/oop.inline.hpp"
  53 #include "oops/symbol.hpp"
  54 #include "prims/jvmtiExport.hpp"
  55 #include "prims/methodHandles.hpp"
  56 #include "prims/nativeLookup.hpp"
  57 #include "runtime/atomic.hpp"
  58 #include "runtime/deoptimization.hpp"
  59 #include "runtime/fieldDescriptor.inline.hpp"
  60 #include "runtime/frame.inline.hpp"
  61 #include "runtime/handles.inline.hpp"
  62 #include "runtime/icache.hpp"
  63 #include "runtime/interfaceSupport.inline.hpp"
  64 #include "runtime/java.hpp"
  65 #include "runtime/javaCalls.hpp"
  66 #include "runtime/jfieldIDWorkaround.hpp"
  67 #include "runtime/osThread.hpp"
  68 #include "runtime/sharedRuntime.hpp"
  69 #include "runtime/stackWatermarkSet.hpp"
  70 #include "runtime/stubRoutines.hpp"
  71 #include "runtime/synchronizer.hpp"
  72 #include "runtime/threadCritical.hpp"
  73 #include "utilities/align.hpp"
  74 #include "utilities/copy.hpp"
  75 #include "utilities/events.hpp"

  76 #ifdef COMPILER2
  77 #include "opto/runtime.hpp"
  78 #endif
  79 
  80 // Helper class to access current interpreter state
  81 class LastFrameAccessor : public StackObj {
  82   frame _last_frame;
  83 public:
  84   LastFrameAccessor(JavaThread* current) {
  85     assert(current == Thread::current(), "sanity");
  86     _last_frame = current->last_frame();
  87   }
  88   bool is_interpreted_frame() const              { return _last_frame.is_interpreted_frame(); }
  89   Method*   method() const                       { return _last_frame.interpreter_frame_method(); }
  90   address   bcp() const                          { return _last_frame.interpreter_frame_bcp(); }
  91   int       bci() const                          { return _last_frame.interpreter_frame_bci(); }
  92   address   mdp() const                          { return _last_frame.interpreter_frame_mdp(); }
  93 
  94   void      set_bcp(address bcp)                 { _last_frame.interpreter_frame_set_bcp(bcp); }
  95   void      set_mdp(address dp)                  { _last_frame.interpreter_frame_set_mdp(dp); }

 137     if (mdo != NULL) {
 138       NEEDS_CLEANUP;
 139       last_frame.set_mdp(mdo->bci_to_dp(last_frame.bci()));
 140     }
 141   }
 142 }
 143 
 144 //------------------------------------------------------------------------------------------------------------------------
 145 // Constants
 146 
 147 
 148 JRT_ENTRY(void, InterpreterRuntime::ldc(JavaThread* current, bool wide))
 149   // access constant pool
 150   LastFrameAccessor last_frame(current);
 151   ConstantPool* pool = last_frame.method()->constants();
 152   int index = wide ? last_frame.get_index_u2(Bytecodes::_ldc_w) : last_frame.get_index_u1(Bytecodes::_ldc);
 153   constantTag tag = pool->tag_at(index);
 154 
 155   assert (tag.is_unresolved_klass() || tag.is_klass(), "wrong ldc call");
 156   Klass* klass = pool->klass_at(index, CHECK);
 157   oop java_class = klass->java_mirror();


 158   current->set_vm_result(java_class);
 159 JRT_END
 160 
 161 JRT_ENTRY(void, InterpreterRuntime::resolve_ldc(JavaThread* current, Bytecodes::Code bytecode)) {
 162   assert(bytecode == Bytecodes::_ldc ||
 163          bytecode == Bytecodes::_ldc_w ||
 164          bytecode == Bytecodes::_ldc2_w ||
 165          bytecode == Bytecodes::_fast_aldc ||
 166          bytecode == Bytecodes::_fast_aldc_w, "wrong bc");
 167   ResourceMark rm(current);
 168   const bool is_fast_aldc = (bytecode == Bytecodes::_fast_aldc ||
 169                              bytecode == Bytecodes::_fast_aldc_w);
 170   LastFrameAccessor last_frame(current);
 171   methodHandle m (current, last_frame.method());
 172   Bytecode_loadconstant ldc(m, last_frame.bci());
 173 
 174   // Double-check the size.  (Condy can have any type.)
 175   BasicType type = ldc.result_type();
 176   switch (type2size[type]) {
 177   case 2: guarantee(bytecode == Bytecodes::_ldc2_w, ""); break;

 201   current->set_vm_result(result);
 202   if (!is_fast_aldc) {
 203     // Tell the interpreter how to unbox the primitive.
 204     guarantee(java_lang_boxing_object::is_instance(result, type), "");
 205     int offset = java_lang_boxing_object::value_offset(type);
 206     intptr_t flags = ((as_TosState(type) << ConstantPoolCacheEntry::tos_state_shift)
 207                       | (offset & ConstantPoolCacheEntry::field_index_mask));
 208     current->set_vm_result_2((Metadata*)flags);
 209   }
 210 }
 211 JRT_END
 212 
 213 
 214 //------------------------------------------------------------------------------------------------------------------------
 215 // Allocation
 216 
 217 JRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* current, ConstantPool* pool, int index))
 218   Klass* k = pool->klass_at(index, CHECK);
 219   InstanceKlass* klass = InstanceKlass::cast(k);
 220 




 221   // Make sure we are not instantiating an abstract klass
 222   klass->check_valid_for_instantiation(true, CHECK);
 223 
 224   // Make sure klass is initialized
 225   klass->initialize(CHECK);
 226 
 227   // At this point the class may not be fully initialized
 228   // because of recursive initialization. If it is fully
 229   // initialized & has_finalized is not set, we rewrite
 230   // it into its fast version (Note: no locking is needed
 231   // here since this is an atomic byte write and can be
 232   // done more than once).
 233   //
 234   // Note: In case of classes with has_finalized we don't
 235   //       rewrite since that saves us an extra check in
 236   //       the fast version which then would call the
 237   //       slow version anyway (and do a call back into
 238   //       Java).
 239   //       If we have a breakpoint, then we don't rewrite
 240   //       because the _breakpoint bytecode would be lost.
 241   oop obj = klass->allocate_instance(CHECK);
 242   current->set_vm_result(obj);
 243 JRT_END
 244 


























































































































































 245 
 246 JRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* current, BasicType type, jint size))
 247   oop obj = oopFactory::new_typeArray(type, size, CHECK);
 248   current->set_vm_result(obj);
 249 JRT_END
 250 
 251 
 252 JRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* current, ConstantPool* pool, int index, jint size))
 253   Klass*    klass = pool->klass_at(index, CHECK);
 254   objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);







 255   current->set_vm_result(obj);
 256 JRT_END
 257 










 258 
 259 JRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* current, jint* first_size_address))
 260   // We may want to pass in more arguments - could make this slightly faster
 261   LastFrameAccessor last_frame(current);
 262   ConstantPool* constants = last_frame.method()->constants();
 263   int          i = last_frame.get_index_u2(Bytecodes::_multianewarray);
 264   Klass* klass   = constants->klass_at(i, CHECK);

 265   int   nof_dims = last_frame.number_of_dimensions();
 266   assert(klass->is_klass(), "not a class");
 267   assert(nof_dims >= 1, "multianewarray rank must be nonzero");
 268 




 269   // We must create an array of jints to pass to multi_allocate.
 270   ResourceMark rm(current);
 271   const int small_dims = 10;
 272   jint dim_array[small_dims];
 273   jint *dims = &dim_array[0];
 274   if (nof_dims > small_dims) {
 275     dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
 276   }
 277   for (int index = 0; index < nof_dims; index++) {
 278     // offset from first_size_address is addressed as local[index]
 279     int n = Interpreter::local_offset_in_bytes(index)/jintSize;
 280     dims[index] = first_size_address[n];
 281   }
 282   oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
 283   current->set_vm_result(obj);
 284 JRT_END
 285 
 286 
 287 JRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* current, oopDesc* obj))
 288   assert(oopDesc::is_oop(obj), "must be a valid oop");
 289   assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
 290   InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
 291 JRT_END
 292 























 293 
 294 // Quicken instance-of and check-cast bytecodes
 295 JRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* current))
 296   // Force resolving; quicken the bytecode
 297   LastFrameAccessor last_frame(current);
 298   int which = last_frame.get_index_u2(Bytecodes::_checkcast);
 299   ConstantPool* cpool = last_frame.method()->constants();
 300   // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
 301   // program we might have seen an unquick'd bytecode in the interpreter but have another
 302   // thread quicken the bytecode before we get here.
 303   // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
 304   Klass* klass = cpool->klass_at(which, CHECK);
 305   current->set_vm_result_2(klass);
 306 JRT_END
 307 
 308 
 309 //------------------------------------------------------------------------------------------------------------------------
 310 // Exceptions
 311 
 312 void InterpreterRuntime::note_trap_inner(JavaThread* current, int reason,

 599 // and therefore we don't have the receiver object at our fingertips. (Though,
 600 // on some platforms the receiver still resides in a register...). Thus,
 601 // we have no choice but print an error message not containing the receiver
 602 // type.
 603 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorWithMethod(JavaThread* current,
 604                                                                         Method* missingMethod))
 605   ResourceMark rm(current);
 606   assert(missingMethod != NULL, "sanity");
 607   methodHandle m(current, missingMethod);
 608   LinkResolver::throw_abstract_method_error(m, THREAD);
 609 JRT_END
 610 
 611 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorVerbose(JavaThread* current,
 612                                                                      Klass* recvKlass,
 613                                                                      Method* missingMethod))
 614   ResourceMark rm(current);
 615   methodHandle mh = methodHandle(current, missingMethod);
 616   LinkResolver::throw_abstract_method_error(mh, recvKlass, THREAD);
 617 JRT_END
 618 




 619 
 620 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* current))
 621   THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
 622 JRT_END
 623 
 624 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose(JavaThread* current,
 625                                                                               Klass* recvKlass,
 626                                                                               Klass* interfaceKlass))
 627   ResourceMark rm(current);
 628   char buf[1000];
 629   buf[0] = '\0';
 630   jio_snprintf(buf, sizeof(buf),
 631                "Class %s does not implement the requested interface %s",
 632                recvKlass ? recvKlass->external_name() : "NULL",
 633                interfaceKlass ? interfaceKlass->external_name() : "NULL");
 634   THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
 635 JRT_END
 636 
 637 JRT_ENTRY(void, InterpreterRuntime::throw_NullPointerException(JavaThread* current))
 638   THROW(vmSymbols::java_lang_NullPointerException());
 639 JRT_END
 640 
 641 //------------------------------------------------------------------------------------------------------------------------
 642 // Fields
 643 //
 644 
 645 void InterpreterRuntime::resolve_get_put(JavaThread* current, Bytecodes::Code bytecode) {
 646   // resolve field
 647   fieldDescriptor info;
 648   LastFrameAccessor last_frame(current);
 649   constantPoolHandle pool(current, last_frame.method()->constants());
 650   methodHandle m(current, last_frame.method());
 651   bool is_put    = (bytecode == Bytecodes::_putfield  || bytecode == Bytecodes::_nofast_putfield ||
 652                     bytecode == Bytecodes::_putstatic);
 653   bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic);

 654 
 655   {
 656     JvmtiHideSingleStepping jhss(current);
 657     JavaThread* THREAD = current; // For exception macros.
 658     LinkResolver::resolve_field_access(info, pool, last_frame.get_index_u2_cpcache(bytecode),
 659                                        m, bytecode, CHECK);
 660   } // end JvmtiHideSingleStepping
 661 
 662   // check if link resolution caused cpCache to be updated
 663   ConstantPoolCacheEntry* cp_cache_entry = last_frame.cache_entry();
 664   if (cp_cache_entry->is_resolved(bytecode)) return;
 665 
 666   // compute auxiliary field attributes
 667   TosState state  = as_TosState(info.field_type());
 668 
 669   // Resolution of put instructions on final fields is delayed. That is required so that
 670   // exceptions are thrown at the correct place (when the instruction is actually invoked).
 671   // If we do not resolve an instruction in the current pass, leaving the put_code
 672   // set to zero will cause the next put instruction to the same field to reresolve.
 673 

 678   // initializer method <init>. If resolution were not inhibited, a putfield
 679   // in an initializer method could be resolved in the initializer. Subsequent
 680   // putfield instructions to the same field would then use cached information.
 681   // As a result, those instructions would not pass through the VM. That is,
 682   // checks in resolve_field_access() would not be executed for those instructions
 683   // and the required IllegalAccessError would not be thrown.
 684   //
 685   // Also, we need to delay resolving getstatic and putstatic instructions until the
 686   // class is initialized.  This is required so that access to the static
 687   // field will call the initialization function every time until the class
 688   // is completely initialized ala. in 2.17.5 in JVM Specification.
 689   InstanceKlass* klass = info.field_holder();
 690   bool uninitialized_static = is_static && !klass->is_initialized();
 691   bool has_initialized_final_update = info.field_holder()->major_version() >= 53 &&
 692                                       info.has_initialized_final_update();
 693   assert(!(has_initialized_final_update && !info.access_flags().is_final()), "Fields with initialized final updates must be final");
 694 
 695   Bytecodes::Code get_code = (Bytecodes::Code)0;
 696   Bytecodes::Code put_code = (Bytecodes::Code)0;
 697   if (!uninitialized_static) {
 698     get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield);
 699     if ((is_put && !has_initialized_final_update) || !info.access_flags().is_final()) {
 700       put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);






 701     }
 702   }
 703 
 704   cp_cache_entry->set_field(
 705     get_code,
 706     put_code,
 707     info.field_holder(),
 708     info.index(),
 709     info.offset(),
 710     state,
 711     info.access_flags().is_final(),
 712     info.access_flags().is_volatile()


 713   );
 714 }
 715 
 716 
 717 //------------------------------------------------------------------------------------------------------------------------
 718 // Synchronization
 719 //
 720 // The interpreter's synchronization code is factored out so that it can
 721 // be shared by method invocation and synchronized blocks.
 722 //%note synchronization_3
 723 
 724 //%note monitor_1
 725 JRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* current, BasicObjectLock* elem))
 726 #ifdef ASSERT
 727   current->last_frame().interpreter_frame_verify_monitor(elem);
 728 #endif
 729   Handle h_obj(current, elem->obj());
 730   assert(Universe::heap()->is_in_or_null(h_obj()),
 731          "must be NULL or an object");
 732   ObjectSynchronizer::enter(h_obj, elem->lock(), current);

 924   {
 925     JvmtiHideSingleStepping jhss(current);
 926     JavaThread* THREAD = current; // For exception macros.
 927     LinkResolver::resolve_invoke(info, Handle(), pool,
 928                                  index, bytecode, CHECK);
 929   } // end JvmtiHideSingleStepping
 930 
 931   ConstantPoolCacheEntry* cp_cache_entry = pool->invokedynamic_cp_cache_entry_at(index);
 932   cp_cache_entry->set_dynamic_call(pool, info);
 933 }
 934 
 935 // This function is the interface to the assembly code. It returns the resolved
 936 // cpCache entry.  This doesn't safepoint, but the helper routines safepoint.
 937 // This function will check for redefinition!
 938 JRT_ENTRY(void, InterpreterRuntime::resolve_from_cache(JavaThread* current, Bytecodes::Code bytecode)) {
 939   switch (bytecode) {
 940   case Bytecodes::_getstatic:
 941   case Bytecodes::_putstatic:
 942   case Bytecodes::_getfield:
 943   case Bytecodes::_putfield:

 944     resolve_get_put(current, bytecode);
 945     break;
 946   case Bytecodes::_invokevirtual:
 947   case Bytecodes::_invokespecial:
 948   case Bytecodes::_invokestatic:
 949   case Bytecodes::_invokeinterface:
 950     resolve_invoke(current, bytecode);
 951     break;
 952   case Bytecodes::_invokehandle:
 953     resolve_invokehandle(current);
 954     break;
 955   case Bytecodes::_invokedynamic:
 956     resolve_invokedynamic(current);
 957     break;
 958   default:
 959     fatal("unexpected bytecode: %s", Bytecodes::name(bytecode));
 960     break;
 961   }
 962 }
 963 JRT_END

1121   // This function is called by the interpreter when the return poll found a reason
1122   // to call the VM. The reason could be that we are returning into a not yet safe
1123   // to access frame. We handle that below.
1124   // Note that this path does not check for single stepping, because we do not want
1125   // to single step when unwinding frames for an exception being thrown. Instead,
1126   // such single stepping code will use the safepoint table, which will use the
1127   // InterpreterRuntime::at_safepoint callback.
1128   StackWatermarkSet::before_unwind(current);
1129 JRT_END
1130 
1131 JRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread* current, oopDesc* obj,
1132                                                       ConstantPoolCacheEntry *cp_entry))
1133 
1134   // check the access_flags for the field in the klass
1135 
1136   InstanceKlass* ik = InstanceKlass::cast(cp_entry->f1_as_klass());
1137   int index = cp_entry->field_index();
1138   if ((ik->field_access_flags(index) & JVM_ACC_FIELD_ACCESS_WATCHED) == 0) return;
1139 
1140   bool is_static = (obj == NULL);

1141   HandleMark hm(current);
1142 
1143   Handle h_obj;
1144   if (!is_static) {
1145     // non-static field accessors have an object, but we need a handle
1146     h_obj = Handle(current, obj);
1147   }
1148   InstanceKlass* cp_entry_f1 = InstanceKlass::cast(cp_entry->f1_as_klass());
1149   jfieldID fid = jfieldIDWorkaround::to_jfieldID(cp_entry_f1, cp_entry->f2_as_index(), is_static);
1150   LastFrameAccessor last_frame(current);
1151   JvmtiExport::post_field_access(current, last_frame.method(), last_frame.bcp(), cp_entry_f1, h_obj, fid);
1152 JRT_END
1153 
1154 JRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread* current, oopDesc* obj,
1155                                                             ConstantPoolCacheEntry *cp_entry, jvalue *value))
1156 
1157   Klass* k = cp_entry->f1_as_klass();
1158 
1159   // check the access_flags for the field in the klass
1160   InstanceKlass* ik = InstanceKlass::cast(k);
1161   int index = cp_entry->field_index();
1162   // bail out if field modifications are not watched
1163   if ((ik->field_access_flags(index) & JVM_ACC_FIELD_MODIFICATION_WATCHED) == 0) return;
1164 
1165   char sig_type = '\0';
1166 
1167   switch(cp_entry->flag_state()) {
1168     case btos: sig_type = JVM_SIGNATURE_BYTE;    break;
1169     case ztos: sig_type = JVM_SIGNATURE_BOOLEAN; break;
1170     case ctos: sig_type = JVM_SIGNATURE_CHAR;    break;
1171     case stos: sig_type = JVM_SIGNATURE_SHORT;   break;
1172     case itos: sig_type = JVM_SIGNATURE_INT;     break;
1173     case ftos: sig_type = JVM_SIGNATURE_FLOAT;   break;
1174     case atos: sig_type = JVM_SIGNATURE_CLASS;   break;
1175     case ltos: sig_type = JVM_SIGNATURE_LONG;    break;
1176     case dtos: sig_type = JVM_SIGNATURE_DOUBLE;  break;
1177     default:  ShouldNotReachHere(); return;
1178   }






1179   bool is_static = (obj == NULL);

1180 
1181   HandleMark hm(current);
1182   jfieldID fid = jfieldIDWorkaround::to_jfieldID(ik, cp_entry->f2_as_index(), is_static);
1183   jvalue fvalue;
1184 #ifdef _LP64
1185   fvalue = *value;
1186 #else
1187   // Long/double values are stored unaligned and also noncontiguously with
1188   // tagged stacks.  We can't just do a simple assignment even in the non-
1189   // J/D cases because a C++ compiler is allowed to assume that a jvalue is
1190   // 8-byte aligned, and interpreter stack slots are only 4-byte aligned.
1191   // We assume that the two halves of longs/doubles are stored in interpreter
1192   // stack slots in platform-endian order.
1193   jlong_accessor u;
1194   jint* newval = (jint*)value;
1195   u.words[0] = newval[0];
1196   u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
1197   fvalue.j = u.long_value;
1198 #endif // _LP64
1199 
1200   Handle h_obj;
1201   if (!is_static) {
1202     // non-static field accessors have an object, but we need a handle

   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "jvm_io.h"
  27 #include "classfile/javaClasses.inline.hpp"
  28 #include "classfile/symbolTable.hpp"
  29 #include "classfile/systemDictionary.hpp"
  30 #include "classfile/vmClasses.hpp"
  31 #include "classfile/vmSymbols.hpp"
  32 #include "code/codeCache.hpp"
  33 #include "compiler/compilationPolicy.hpp"
  34 #include "compiler/compileBroker.hpp"
  35 #include "compiler/disassembler.hpp"
  36 #include "gc/shared/barrierSetNMethod.hpp"
  37 #include "gc/shared/collectedHeap.hpp"
  38 #include "interpreter/interpreter.hpp"
  39 #include "interpreter/interpreterRuntime.hpp"
  40 #include "interpreter/linkResolver.hpp"
  41 #include "interpreter/templateTable.hpp"
  42 #include "logging/log.hpp"
  43 #include "memory/oopFactory.hpp"
  44 #include "memory/resourceArea.hpp"
  45 #include "memory/universe.hpp"
  46 #include "oops/constantPool.hpp"
  47 #include "oops/cpCache.inline.hpp"
  48 #include "oops/flatArrayKlass.hpp"
  49 #include "oops/flatArrayOop.inline.hpp"
  50 #include "oops/inlineKlass.inline.hpp"
  51 #include "oops/instanceKlass.inline.hpp"
  52 #include "oops/klass.inline.hpp"
  53 #include "oops/methodData.hpp"
  54 #include "oops/objArrayKlass.hpp"
  55 #include "oops/objArrayOop.inline.hpp"
  56 #include "oops/oop.inline.hpp"
  57 #include "oops/symbol.hpp"
  58 #include "prims/jvmtiExport.hpp"
  59 #include "prims/methodHandles.hpp"
  60 #include "prims/nativeLookup.hpp"
  61 #include "runtime/atomic.hpp"
  62 #include "runtime/deoptimization.hpp"
  63 #include "runtime/fieldDescriptor.inline.hpp"
  64 #include "runtime/frame.inline.hpp"
  65 #include "runtime/handles.inline.hpp"
  66 #include "runtime/icache.hpp"
  67 #include "runtime/interfaceSupport.inline.hpp"
  68 #include "runtime/java.hpp"
  69 #include "runtime/javaCalls.hpp"
  70 #include "runtime/jfieldIDWorkaround.hpp"
  71 #include "runtime/osThread.hpp"
  72 #include "runtime/sharedRuntime.hpp"
  73 #include "runtime/stackWatermarkSet.hpp"
  74 #include "runtime/stubRoutines.hpp"
  75 #include "runtime/synchronizer.hpp"
  76 #include "runtime/threadCritical.hpp"
  77 #include "utilities/align.hpp"
  78 #include "utilities/copy.hpp"
  79 #include "utilities/events.hpp"
  80 #include "utilities/globalDefinitions.hpp"
  81 #ifdef COMPILER2
  82 #include "opto/runtime.hpp"
  83 #endif
  84 
  85 // Helper class to access current interpreter state
  86 class LastFrameAccessor : public StackObj {
  87   frame _last_frame;
  88 public:
  89   LastFrameAccessor(JavaThread* current) {
  90     assert(current == Thread::current(), "sanity");
  91     _last_frame = current->last_frame();
  92   }
  93   bool is_interpreted_frame() const              { return _last_frame.is_interpreted_frame(); }
  94   Method*   method() const                       { return _last_frame.interpreter_frame_method(); }
  95   address   bcp() const                          { return _last_frame.interpreter_frame_bcp(); }
  96   int       bci() const                          { return _last_frame.interpreter_frame_bci(); }
  97   address   mdp() const                          { return _last_frame.interpreter_frame_mdp(); }
  98 
  99   void      set_bcp(address bcp)                 { _last_frame.interpreter_frame_set_bcp(bcp); }
 100   void      set_mdp(address dp)                  { _last_frame.interpreter_frame_set_mdp(dp); }

 142     if (mdo != NULL) {
 143       NEEDS_CLEANUP;
 144       last_frame.set_mdp(mdo->bci_to_dp(last_frame.bci()));
 145     }
 146   }
 147 }
 148 
 149 //------------------------------------------------------------------------------------------------------------------------
 150 // Constants
 151 
 152 
 153 JRT_ENTRY(void, InterpreterRuntime::ldc(JavaThread* current, bool wide))
 154   // access constant pool
 155   LastFrameAccessor last_frame(current);
 156   ConstantPool* pool = last_frame.method()->constants();
 157   int index = wide ? last_frame.get_index_u2(Bytecodes::_ldc_w) : last_frame.get_index_u1(Bytecodes::_ldc);
 158   constantTag tag = pool->tag_at(index);
 159 
 160   assert (tag.is_unresolved_klass() || tag.is_klass(), "wrong ldc call");
 161   Klass* klass = pool->klass_at(index, CHECK);
 162   oop java_class = tag.is_Qdescriptor_klass()
 163                       ? InlineKlass::cast(klass)->val_mirror()
 164                       : klass->java_mirror();
 165   current->set_vm_result(java_class);
 166 JRT_END
 167 
 168 JRT_ENTRY(void, InterpreterRuntime::resolve_ldc(JavaThread* current, Bytecodes::Code bytecode)) {
 169   assert(bytecode == Bytecodes::_ldc ||
 170          bytecode == Bytecodes::_ldc_w ||
 171          bytecode == Bytecodes::_ldc2_w ||
 172          bytecode == Bytecodes::_fast_aldc ||
 173          bytecode == Bytecodes::_fast_aldc_w, "wrong bc");
 174   ResourceMark rm(current);
 175   const bool is_fast_aldc = (bytecode == Bytecodes::_fast_aldc ||
 176                              bytecode == Bytecodes::_fast_aldc_w);
 177   LastFrameAccessor last_frame(current);
 178   methodHandle m (current, last_frame.method());
 179   Bytecode_loadconstant ldc(m, last_frame.bci());
 180 
 181   // Double-check the size.  (Condy can have any type.)
 182   BasicType type = ldc.result_type();
 183   switch (type2size[type]) {
 184   case 2: guarantee(bytecode == Bytecodes::_ldc2_w, ""); break;

 208   current->set_vm_result(result);
 209   if (!is_fast_aldc) {
 210     // Tell the interpreter how to unbox the primitive.
 211     guarantee(java_lang_boxing_object::is_instance(result, type), "");
 212     int offset = java_lang_boxing_object::value_offset(type);
 213     intptr_t flags = ((as_TosState(type) << ConstantPoolCacheEntry::tos_state_shift)
 214                       | (offset & ConstantPoolCacheEntry::field_index_mask));
 215     current->set_vm_result_2((Metadata*)flags);
 216   }
 217 }
 218 JRT_END
 219 
 220 
 221 //------------------------------------------------------------------------------------------------------------------------
 222 // Allocation
 223 
 224 JRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* current, ConstantPool* pool, int index))
 225   Klass* k = pool->klass_at(index, CHECK);
 226   InstanceKlass* klass = InstanceKlass::cast(k);
 227 
 228   if (klass->is_inline_klass()) {
 229     THROW(vmSymbols::java_lang_InstantiationError());
 230   }
 231 
 232   // Make sure we are not instantiating an abstract klass
 233   klass->check_valid_for_instantiation(true, CHECK);
 234 
 235   // Make sure klass is initialized
 236   klass->initialize(CHECK);
 237 
 238   // At this point the class may not be fully initialized
 239   // because of recursive initialization. If it is fully
 240   // initialized & has_finalized is not set, we rewrite
 241   // it into its fast version (Note: no locking is needed
 242   // here since this is an atomic byte write and can be
 243   // done more than once).
 244   //
 245   // Note: In case of classes with has_finalized we don't
 246   //       rewrite since that saves us an extra check in
 247   //       the fast version which then would call the
 248   //       slow version anyway (and do a call back into
 249   //       Java).
 250   //       If we have a breakpoint, then we don't rewrite
 251   //       because the _breakpoint bytecode would be lost.
 252   oop obj = klass->allocate_instance(CHECK);
 253   current->set_vm_result(obj);
 254 JRT_END
 255 
 256 JRT_ENTRY(void, InterpreterRuntime::defaultvalue(JavaThread* current, ConstantPool* pool, int index))
 257   // Getting the InlineKlass
 258   Klass* k = pool->klass_at(index, CHECK);
 259   if (!k->is_inline_klass()) {
 260     // inconsistency with 'new' which throws an InstantiationError
 261     // in the future, defaultvalue will just return null instead of throwing an exception
 262     THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
 263   }
 264   assert(k->is_inline_klass(), "defaultvalue argument must be the inline type class");
 265   InlineKlass* vklass = InlineKlass::cast(k);
 266 
 267   vklass->initialize(CHECK);
 268   oop res = vklass->default_value();
 269   current->set_vm_result(res);
 270 JRT_END
 271 
 272 JRT_ENTRY(int, InterpreterRuntime::withfield(JavaThread* current, ConstantPoolCacheEntry* cpe, uintptr_t ptr))
 273   oop obj = NULL;
 274   int recv_offset = type2size[as_BasicType(cpe->flag_state())];
 275   assert(frame::interpreter_frame_expression_stack_direction() == -1, "currently is -1 on all platforms");
 276   int ret_adj = (recv_offset + type2size[T_OBJECT] )* AbstractInterpreter::stackElementSize;
 277   obj = (oopDesc*)(((uintptr_t*)ptr)[recv_offset * Interpreter::stackElementWords]);
 278   if (obj == NULL) {
 279     THROW_(vmSymbols::java_lang_NullPointerException(), ret_adj);
 280   }
 281   assert(oopDesc::is_oop(obj), "Verifying receiver");
 282   assert(obj->klass()->is_inline_klass(), "Must have been checked during resolution");
 283   instanceHandle old_value_h(THREAD, (instanceOop)obj);
 284   oop ref = NULL;
 285   if (cpe->flag_state() == atos) {
 286     ref = *(oopDesc**)ptr;
 287   }
 288   Handle ref_h(THREAD, ref);
 289   InlineKlass* ik = InlineKlass::cast(old_value_h()->klass());
 290   instanceOop new_value = ik->allocate_instance_buffer(CHECK_(ret_adj));
 291   Handle new_value_h = Handle(THREAD, new_value);
 292   ik->inline_copy_oop_to_new_oop(old_value_h(), new_value_h());
 293   int offset = cpe->f2_as_offset();
 294   switch(cpe->flag_state()) {
 295     case ztos:
 296       new_value_h()->bool_field_put(offset, (jboolean)(*(jint*)ptr));
 297       break;
 298     case btos:
 299       new_value_h()->byte_field_put(offset, (jbyte)(*(jint*)ptr));
 300       break;
 301     case ctos:
 302       new_value_h()->char_field_put(offset, (jchar)(*(jint*)ptr));
 303       break;
 304     case stos:
 305       new_value_h()->short_field_put(offset, (jshort)(*(jint*)ptr));
 306       break;
 307     case itos:
 308       new_value_h()->int_field_put(offset, (*(jint*)ptr));
 309       break;
 310     case ltos:
 311       new_value_h()->long_field_put(offset, *(jlong*)ptr);
 312       break;
 313     case ftos:
 314       new_value_h()->float_field_put(offset, *(jfloat*)ptr);
 315       break;
 316     case dtos:
 317       new_value_h()->double_field_put(offset, *(jdouble*)ptr);
 318       break;
 319     case atos:
 320       {
 321         if (cpe->is_null_free_inline_type())  {
 322           if (!cpe->is_inlined()) {
 323               if (ref_h() == NULL) {
 324                 THROW_(vmSymbols::java_lang_NullPointerException(), ret_adj);
 325               }
 326               new_value_h()->obj_field_put(offset, ref_h());
 327             } else {
 328               int field_index = cpe->field_index();
 329               InlineKlass* field_ik = InlineKlass::cast(ik->get_inline_type_field_klass(field_index));
 330               field_ik->write_inlined_field(new_value_h(), offset, ref_h(), CHECK_(ret_adj));
 331             }
 332         } else {
 333           new_value_h()->obj_field_put(offset, ref_h());
 334         }
 335       }
 336       break;
 337     default:
 338       ShouldNotReachHere();
 339   }
 340   current->set_vm_result(new_value_h());
 341   return ret_adj;
 342 JRT_END
 343 
 344 JRT_ENTRY(void, InterpreterRuntime::uninitialized_static_inline_type_field(JavaThread* current, oopDesc* mirror, int index))
 345   // The interpreter tries to access an inline static field that has not been initialized.
 346   // This situation can happen in different scenarios:
 347   //   1 - if the load or initialization of the field failed during step 8 of
 348   //       the initialization of the holder of the field, in this case the access to the field
 349   //       must fail
 350   //   2 - it can also happen when the initialization of the holder class triggered the initialization of
 351   //       another class which accesses this field in its static initializer, in this case the
 352   //       access must succeed to allow circularity
 353   // The code below tries to load and initialize the field's class again before returning the default value.
 354   // If the field was not initialized because of an error, a exception should be thrown.
 355   // If the class is being initialized, the default value is returned.
 356   instanceHandle mirror_h(THREAD, (instanceOop)mirror);
 357   InstanceKlass* klass = InstanceKlass::cast(java_lang_Class::as_Klass(mirror));
 358   assert(klass->field_signature(index)->is_Q_signature(), "Sanity check");
 359   if (klass->is_being_initialized() && klass->is_reentrant_initialization(THREAD)) {
 360     int offset = klass->field_offset(index);
 361     Klass* field_k = klass->get_inline_type_field_klass_or_null(index);
 362     if (field_k == NULL) {
 363       field_k = SystemDictionary::resolve_or_fail(klass->field_signature(index)->fundamental_name(THREAD),
 364           Handle(THREAD, klass->class_loader()),
 365           Handle(THREAD, klass->protection_domain()),
 366           true, CHECK);
 367       assert(field_k != NULL, "Should have been loaded or an exception thrown above");
 368       klass->set_inline_type_field_klass(index, field_k);
 369     }
 370     field_k->initialize(CHECK);
 371     oop defaultvalue = InlineKlass::cast(field_k)->default_value();
 372     // It is safe to initialized the static field because 1) the current thread is the initializing thread
 373     // and is the only one that can access it, and 2) the field is actually not initialized (i.e. null)
 374     // otherwise the JVM should not be executing this code.
 375     mirror->obj_field_put(offset, defaultvalue);
 376     current->set_vm_result(defaultvalue);
 377   } else {
 378     assert(klass->is_in_error_state(), "If not initializing, initialization must have failed to get there");
 379     ResourceMark rm(THREAD);
 380     const char* desc = "Could not initialize class ";
 381     const char* className = klass->external_name();
 382     size_t msglen = strlen(desc) + strlen(className) + 1;
 383     char* message = NEW_RESOURCE_ARRAY(char, msglen);
 384     if (NULL == message) {
 385       // Out of memory: can't create detailed error message
 386       THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), className);
 387     } else {
 388       jio_snprintf(message, msglen, "%s%s", desc, className);
 389       THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), message);
 390     }
 391   }
 392 JRT_END
 393 
 394 JRT_ENTRY(void, InterpreterRuntime::read_inlined_field(JavaThread* current, oopDesc* obj, int index, Klass* field_holder))
 395   Handle obj_h(THREAD, obj);
 396 
 397   assert(oopDesc::is_oop(obj), "Sanity check");
 398 
 399   assert(field_holder->is_instance_klass(), "Sanity check");
 400   InstanceKlass* klass = InstanceKlass::cast(field_holder);
 401 
 402   assert(klass->field_is_inlined(index), "Sanity check");
 403 
 404   InlineKlass* field_vklass = InlineKlass::cast(klass->get_inline_type_field_klass(index));
 405   assert(field_vklass->is_initialized(), "Must be initialized at this point");
 406 
 407   oop res = field_vklass->read_inlined_field(obj_h(), klass->field_offset(index), CHECK);
 408   current->set_vm_result(res);
 409 JRT_END
 410 
 411 JRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* current, BasicType type, jint size))
 412   oop obj = oopFactory::new_typeArray(type, size, CHECK);
 413   current->set_vm_result(obj);
 414 JRT_END
 415 
 416 
 417 JRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* current, ConstantPool* pool, int index, jint size))
 418   Klass*    klass = pool->klass_at(index, CHECK);
 419   bool      is_qtype_desc = pool->tag_at(index).is_Qdescriptor_klass();
 420   arrayOop obj;
 421   if ((!klass->is_array_klass()) && is_qtype_desc) { // Logically creates elements, ensure klass init
 422     klass->initialize(CHECK);
 423     obj = oopFactory::new_flatArray(klass, size, CHECK);
 424   } else {
 425     obj = oopFactory::new_objArray(klass, size, CHECK);
 426   }
 427   current->set_vm_result(obj);
 428 JRT_END
 429 
 430 JRT_ENTRY(void, InterpreterRuntime::value_array_load(JavaThread* current, arrayOopDesc* array, int index))
 431   flatArrayHandle vah(current, (flatArrayOop)array);
 432   oop value_holder = flatArrayOopDesc::value_alloc_copy_from_index(vah, index, CHECK);
 433   current->set_vm_result(value_holder);
 434 JRT_END
 435 
 436 JRT_ENTRY(void, InterpreterRuntime::value_array_store(JavaThread* current, void* val, arrayOopDesc* array, int index))
 437   assert(val != NULL, "can't store null into flat array");
 438   ((flatArrayOop)array)->value_copy_to_index(cast_to_oop(val), index);
 439 JRT_END
 440 
 441 JRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* current, jint* first_size_address))
 442   // We may want to pass in more arguments - could make this slightly faster
 443   LastFrameAccessor last_frame(current);
 444   ConstantPool* constants = last_frame.method()->constants();
 445   int i = last_frame.get_index_u2(Bytecodes::_multianewarray);
 446   Klass* klass = constants->klass_at(i, CHECK);
 447   bool is_qtype = klass->name()->is_Q_array_signature();
 448   int   nof_dims = last_frame.number_of_dimensions();
 449   assert(klass->is_klass(), "not a class");
 450   assert(nof_dims >= 1, "multianewarray rank must be nonzero");
 451 
 452   if (is_qtype) { // Logically creates elements, ensure klass init
 453     klass->initialize(CHECK);
 454   }
 455 
 456   // We must create an array of jints to pass to multi_allocate.
 457   ResourceMark rm(current);
 458   const int small_dims = 10;
 459   jint dim_array[small_dims];
 460   jint *dims = &dim_array[0];
 461   if (nof_dims > small_dims) {
 462     dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
 463   }
 464   for (int index = 0; index < nof_dims; index++) {
 465     // offset from first_size_address is addressed as local[index]
 466     int n = Interpreter::local_offset_in_bytes(index)/jintSize;
 467     dims[index] = first_size_address[n];
 468   }
 469   oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
 470   current->set_vm_result(obj);
 471 JRT_END
 472 
 473 
 474 JRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* current, oopDesc* obj))
 475   assert(oopDesc::is_oop(obj), "must be a valid oop");
 476   assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
 477   InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
 478 JRT_END
 479 
 480 JRT_ENTRY(jboolean, InterpreterRuntime::is_substitutable(JavaThread* current, oopDesc* aobj, oopDesc* bobj))
 481   assert(oopDesc::is_oop(aobj) && oopDesc::is_oop(bobj), "must be valid oops");
 482 
 483   Handle ha(THREAD, aobj);
 484   Handle hb(THREAD, bobj);
 485   JavaValue result(T_BOOLEAN);
 486   JavaCallArguments args;
 487   args.push_oop(ha);
 488   args.push_oop(hb);
 489   methodHandle method(current, Universe::is_substitutable_method());
 490   JavaCalls::call(&result, method, &args, THREAD);
 491   if (HAS_PENDING_EXCEPTION) {
 492     // Something really bad happened because isSubstitutable() should not throw exceptions
 493     // If it is an error, just let it propagate
 494     // If it is an exception, wrap it into an InternalError
 495     if (!PENDING_EXCEPTION->is_a(vmClasses::Error_klass())) {
 496       Handle e(THREAD, PENDING_EXCEPTION);
 497       CLEAR_PENDING_EXCEPTION;
 498       THROW_MSG_CAUSE_(vmSymbols::java_lang_InternalError(), "Internal error in substitutability test", e, false);
 499     }
 500   }
 501   return result.get_jboolean();
 502 JRT_END
 503 
 504 // Quicken instance-of and check-cast bytecodes
 505 JRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* current))
 506   // Force resolving; quicken the bytecode
 507   LastFrameAccessor last_frame(current);
 508   int which = last_frame.get_index_u2(Bytecodes::_checkcast);
 509   ConstantPool* cpool = last_frame.method()->constants();
 510   // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
 511   // program we might have seen an unquick'd bytecode in the interpreter but have another
 512   // thread quicken the bytecode before we get here.
 513   // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
 514   Klass* klass = cpool->klass_at(which, CHECK);
 515   current->set_vm_result_2(klass);
 516 JRT_END
 517 
 518 
 519 //------------------------------------------------------------------------------------------------------------------------
 520 // Exceptions
 521 
 522 void InterpreterRuntime::note_trap_inner(JavaThread* current, int reason,

 809 // and therefore we don't have the receiver object at our fingertips. (Though,
 810 // on some platforms the receiver still resides in a register...). Thus,
 811 // we have no choice but print an error message not containing the receiver
 812 // type.
 813 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorWithMethod(JavaThread* current,
 814                                                                         Method* missingMethod))
 815   ResourceMark rm(current);
 816   assert(missingMethod != NULL, "sanity");
 817   methodHandle m(current, missingMethod);
 818   LinkResolver::throw_abstract_method_error(m, THREAD);
 819 JRT_END
 820 
 821 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorVerbose(JavaThread* current,
 822                                                                      Klass* recvKlass,
 823                                                                      Method* missingMethod))
 824   ResourceMark rm(current);
 825   methodHandle mh = methodHandle(current, missingMethod);
 826   LinkResolver::throw_abstract_method_error(mh, recvKlass, THREAD);
 827 JRT_END
 828 
 829 JRT_ENTRY(void, InterpreterRuntime::throw_InstantiationError(JavaThread* current))
 830   THROW(vmSymbols::java_lang_InstantiationError());
 831 JRT_END
 832 
 833 
 834 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* current))
 835   THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
 836 JRT_END
 837 
 838 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose(JavaThread* current,
 839                                                                               Klass* recvKlass,
 840                                                                               Klass* interfaceKlass))
 841   ResourceMark rm(current);
 842   char buf[1000];
 843   buf[0] = '\0';
 844   jio_snprintf(buf, sizeof(buf),
 845                "Class %s does not implement the requested interface %s",
 846                recvKlass ? recvKlass->external_name() : "NULL",
 847                interfaceKlass ? interfaceKlass->external_name() : "NULL");
 848   THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
 849 JRT_END
 850 
 851 JRT_ENTRY(void, InterpreterRuntime::throw_NullPointerException(JavaThread* current))
 852   THROW(vmSymbols::java_lang_NullPointerException());
 853 JRT_END
 854 
 855 //------------------------------------------------------------------------------------------------------------------------
 856 // Fields
 857 //
 858 
 859 void InterpreterRuntime::resolve_get_put(JavaThread* current, Bytecodes::Code bytecode) {
 860   // resolve field
 861   fieldDescriptor info;
 862   LastFrameAccessor last_frame(current);
 863   constantPoolHandle pool(current, last_frame.method()->constants());
 864   methodHandle m(current, last_frame.method());
 865   bool is_put    = (bytecode == Bytecodes::_putfield  || bytecode == Bytecodes::_nofast_putfield ||
 866                     bytecode == Bytecodes::_putstatic || bytecode == Bytecodes::_withfield);
 867   bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic);
 868   bool is_inline_type  = bytecode == Bytecodes::_withfield;
 869 
 870   {
 871     JvmtiHideSingleStepping jhss(current);
 872     JavaThread* THREAD = current; // For exception macros.
 873     LinkResolver::resolve_field_access(info, pool, last_frame.get_index_u2_cpcache(bytecode),
 874                                        m, bytecode, CHECK);
 875   } // end JvmtiHideSingleStepping
 876 
 877   // check if link resolution caused cpCache to be updated
 878   ConstantPoolCacheEntry* cp_cache_entry = last_frame.cache_entry();
 879   if (cp_cache_entry->is_resolved(bytecode)) return;
 880 
 881   // compute auxiliary field attributes
 882   TosState state  = as_TosState(info.field_type());
 883 
 884   // Resolution of put instructions on final fields is delayed. That is required so that
 885   // exceptions are thrown at the correct place (when the instruction is actually invoked).
 886   // If we do not resolve an instruction in the current pass, leaving the put_code
 887   // set to zero will cause the next put instruction to the same field to reresolve.
 888 

 893   // initializer method <init>. If resolution were not inhibited, a putfield
 894   // in an initializer method could be resolved in the initializer. Subsequent
 895   // putfield instructions to the same field would then use cached information.
 896   // As a result, those instructions would not pass through the VM. That is,
 897   // checks in resolve_field_access() would not be executed for those instructions
 898   // and the required IllegalAccessError would not be thrown.
 899   //
 900   // Also, we need to delay resolving getstatic and putstatic instructions until the
 901   // class is initialized.  This is required so that access to the static
 902   // field will call the initialization function every time until the class
 903   // is completely initialized ala. in 2.17.5 in JVM Specification.
 904   InstanceKlass* klass = info.field_holder();
 905   bool uninitialized_static = is_static && !klass->is_initialized();
 906   bool has_initialized_final_update = info.field_holder()->major_version() >= 53 &&
 907                                       info.has_initialized_final_update();
 908   assert(!(has_initialized_final_update && !info.access_flags().is_final()), "Fields with initialized final updates must be final");
 909 
 910   Bytecodes::Code get_code = (Bytecodes::Code)0;
 911   Bytecodes::Code put_code = (Bytecodes::Code)0;
 912   if (!uninitialized_static) {
 913     if (is_static) {
 914       get_code = Bytecodes::_getstatic;
 915     } else {
 916       get_code = Bytecodes::_getfield;
 917     }
 918     if (is_put && is_inline_type) {
 919         put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_withfield);
 920     } else if ((is_put && !has_initialized_final_update) || !info.access_flags().is_final()) {
 921         put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
 922     }
 923   }
 924 
 925   cp_cache_entry->set_field(
 926     get_code,
 927     put_code,
 928     info.field_holder(),
 929     info.index(),
 930     info.offset(),
 931     state,
 932     info.access_flags().is_final(),
 933     info.access_flags().is_volatile(),
 934     info.is_inlined(),
 935     info.signature()->is_Q_signature() && info.is_inline_type()
 936   );
 937 }
 938 
 939 
 940 //------------------------------------------------------------------------------------------------------------------------
 941 // Synchronization
 942 //
 943 // The interpreter's synchronization code is factored out so that it can
 944 // be shared by method invocation and synchronized blocks.
 945 //%note synchronization_3
 946 
 947 //%note monitor_1
 948 JRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* current, BasicObjectLock* elem))
 949 #ifdef ASSERT
 950   current->last_frame().interpreter_frame_verify_monitor(elem);
 951 #endif
 952   Handle h_obj(current, elem->obj());
 953   assert(Universe::heap()->is_in_or_null(h_obj()),
 954          "must be NULL or an object");
 955   ObjectSynchronizer::enter(h_obj, elem->lock(), current);

1147   {
1148     JvmtiHideSingleStepping jhss(current);
1149     JavaThread* THREAD = current; // For exception macros.
1150     LinkResolver::resolve_invoke(info, Handle(), pool,
1151                                  index, bytecode, CHECK);
1152   } // end JvmtiHideSingleStepping
1153 
1154   ConstantPoolCacheEntry* cp_cache_entry = pool->invokedynamic_cp_cache_entry_at(index);
1155   cp_cache_entry->set_dynamic_call(pool, info);
1156 }
1157 
1158 // This function is the interface to the assembly code. It returns the resolved
1159 // cpCache entry.  This doesn't safepoint, but the helper routines safepoint.
1160 // This function will check for redefinition!
1161 JRT_ENTRY(void, InterpreterRuntime::resolve_from_cache(JavaThread* current, Bytecodes::Code bytecode)) {
1162   switch (bytecode) {
1163   case Bytecodes::_getstatic:
1164   case Bytecodes::_putstatic:
1165   case Bytecodes::_getfield:
1166   case Bytecodes::_putfield:
1167   case Bytecodes::_withfield:
1168     resolve_get_put(current, bytecode);
1169     break;
1170   case Bytecodes::_invokevirtual:
1171   case Bytecodes::_invokespecial:
1172   case Bytecodes::_invokestatic:
1173   case Bytecodes::_invokeinterface:
1174     resolve_invoke(current, bytecode);
1175     break;
1176   case Bytecodes::_invokehandle:
1177     resolve_invokehandle(current);
1178     break;
1179   case Bytecodes::_invokedynamic:
1180     resolve_invokedynamic(current);
1181     break;
1182   default:
1183     fatal("unexpected bytecode: %s", Bytecodes::name(bytecode));
1184     break;
1185   }
1186 }
1187 JRT_END

1345   // This function is called by the interpreter when the return poll found a reason
1346   // to call the VM. The reason could be that we are returning into a not yet safe
1347   // to access frame. We handle that below.
1348   // Note that this path does not check for single stepping, because we do not want
1349   // to single step when unwinding frames for an exception being thrown. Instead,
1350   // such single stepping code will use the safepoint table, which will use the
1351   // InterpreterRuntime::at_safepoint callback.
1352   StackWatermarkSet::before_unwind(current);
1353 JRT_END
1354 
1355 JRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread* current, oopDesc* obj,
1356                                                       ConstantPoolCacheEntry *cp_entry))
1357 
1358   // check the access_flags for the field in the klass
1359 
1360   InstanceKlass* ik = InstanceKlass::cast(cp_entry->f1_as_klass());
1361   int index = cp_entry->field_index();
1362   if ((ik->field_access_flags(index) & JVM_ACC_FIELD_ACCESS_WATCHED) == 0) return;
1363 
1364   bool is_static = (obj == NULL);
1365   bool is_inlined = cp_entry->is_inlined();
1366   HandleMark hm(current);
1367 
1368   Handle h_obj;
1369   if (!is_static) {
1370     // non-static field accessors have an object, but we need a handle
1371     h_obj = Handle(current, obj);
1372   }
1373   InstanceKlass* cp_entry_f1 = InstanceKlass::cast(cp_entry->f1_as_klass());
1374   jfieldID fid = jfieldIDWorkaround::to_jfieldID(cp_entry_f1, cp_entry->f2_as_index(), is_static, is_inlined);
1375   LastFrameAccessor last_frame(current);
1376   JvmtiExport::post_field_access(current, last_frame.method(), last_frame.bcp(), cp_entry_f1, h_obj, fid);
1377 JRT_END
1378 
1379 JRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread* current, oopDesc* obj,
1380                                                             ConstantPoolCacheEntry *cp_entry, jvalue *value))
1381 
1382   Klass* k = cp_entry->f1_as_klass();
1383 
1384   // check the access_flags for the field in the klass
1385   InstanceKlass* ik = InstanceKlass::cast(k);
1386   int index = cp_entry->field_index();
1387   // bail out if field modifications are not watched
1388   if ((ik->field_access_flags(index) & JVM_ACC_FIELD_MODIFICATION_WATCHED) == 0) return;
1389 
1390   char sig_type = '\0';
1391 
1392   switch(cp_entry->flag_state()) {
1393     case btos: sig_type = JVM_SIGNATURE_BYTE;    break;
1394     case ztos: sig_type = JVM_SIGNATURE_BOOLEAN; break;
1395     case ctos: sig_type = JVM_SIGNATURE_CHAR;    break;
1396     case stos: sig_type = JVM_SIGNATURE_SHORT;   break;
1397     case itos: sig_type = JVM_SIGNATURE_INT;     break;
1398     case ftos: sig_type = JVM_SIGNATURE_FLOAT;   break;
1399     case atos: sig_type = JVM_SIGNATURE_CLASS;   break;
1400     case ltos: sig_type = JVM_SIGNATURE_LONG;    break;
1401     case dtos: sig_type = JVM_SIGNATURE_DOUBLE;  break;
1402     default:  ShouldNotReachHere(); return;
1403   }
1404 
1405   // Both Q-signatures and L-signatures are mapped to atos
1406   if (cp_entry->flag_state() == atos && ik->field_signature(index)->is_Q_signature()) {
1407     sig_type = JVM_SIGNATURE_INLINE_TYPE;
1408   }
1409 
1410   bool is_static = (obj == NULL);
1411   bool is_inlined = cp_entry->is_inlined();
1412 
1413   HandleMark hm(current);
1414   jfieldID fid = jfieldIDWorkaround::to_jfieldID(ik, cp_entry->f2_as_index(), is_static, is_inlined);
1415   jvalue fvalue;
1416 #ifdef _LP64
1417   fvalue = *value;
1418 #else
1419   // Long/double values are stored unaligned and also noncontiguously with
1420   // tagged stacks.  We can't just do a simple assignment even in the non-
1421   // J/D cases because a C++ compiler is allowed to assume that a jvalue is
1422   // 8-byte aligned, and interpreter stack slots are only 4-byte aligned.
1423   // We assume that the two halves of longs/doubles are stored in interpreter
1424   // stack slots in platform-endian order.
1425   jlong_accessor u;
1426   jint* newval = (jint*)value;
1427   u.words[0] = newval[0];
1428   u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
1429   fvalue.j = u.long_value;
1430 #endif // _LP64
1431 
1432   Handle h_obj;
1433   if (!is_static) {
1434     // non-static field accessors have an object, but we need a handle
< prev index next >