< prev index next >

src/hotspot/share/interpreter/interpreterRuntime.cpp

Print this page

   8  *
   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 "classfile/javaClasses.inline.hpp"
  27 #include "classfile/symbolTable.hpp"

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



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

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

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




































































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










 257 
 258 JRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* current, jint* first_size_address))
 259   // We may want to pass in more arguments - could make this slightly faster
 260   LastFrameAccessor last_frame(current);
 261   ConstantPool* constants = last_frame.method()->constants();
 262   int          i = last_frame.get_index_u2(Bytecodes::_multianewarray);
 263   Klass* klass   = constants->klass_at(i, CHECK);
 264   int   nof_dims = last_frame.number_of_dimensions();
 265   assert(klass->is_klass(), "not a class");
 266   assert(nof_dims >= 1, "multianewarray rank must be nonzero");
 267 
 268   // We must create an array of jints to pass to multi_allocate.
 269   ResourceMark rm(current);
 270   const int small_dims = 10;
 271   jint dim_array[small_dims];
 272   jint *dims = &dim_array[0];
 273   if (nof_dims > small_dims) {
 274     dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
 275   }
 276   for (int index = 0; index < nof_dims; index++) {
 277     // offset from first_size_address is addressed as local[index]
 278     int n = Interpreter::local_offset_in_bytes(index)/jintSize;
 279     dims[index] = first_size_address[n];
 280   }
 281   oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
 282   current->set_vm_result(obj);
 283 JRT_END
 284 
 285 
 286 JRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* current, oopDesc* obj))
 287   assert(oopDesc::is_oop(obj), "must be a valid oop");
 288   assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
 289   InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
 290 JRT_END
 291 























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

 608 // and therefore we don't have the receiver object at our fingertips. (Though,
 609 // on some platforms the receiver still resides in a register...). Thus,
 610 // we have no choice but print an error message not containing the receiver
 611 // type.
 612 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorWithMethod(JavaThread* current,
 613                                                                         Method* missingMethod))
 614   ResourceMark rm(current);
 615   assert(missingMethod != nullptr, "sanity");
 616   methodHandle m(current, missingMethod);
 617   LinkResolver::throw_abstract_method_error(m, THREAD);
 618 JRT_END
 619 
 620 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorVerbose(JavaThread* current,
 621                                                                      Klass* recvKlass,
 622                                                                      Method* missingMethod))
 623   ResourceMark rm(current);
 624   methodHandle mh = methodHandle(current, missingMethod);
 625   LinkResolver::throw_abstract_method_error(mh, recvKlass, THREAD);
 626 JRT_END
 627 




 628 
 629 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* current))
 630   THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
 631 JRT_END
 632 
 633 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose(JavaThread* current,
 634                                                                               Klass* recvKlass,
 635                                                                               Klass* interfaceKlass))
 636   ResourceMark rm(current);
 637   char buf[1000];
 638   buf[0] = '\0';
 639   jio_snprintf(buf, sizeof(buf),
 640                "Class %s does not implement the requested interface %s",
 641                recvKlass ? recvKlass->external_name() : "nullptr",
 642                interfaceKlass ? interfaceKlass->external_name() : "nullptr");
 643   THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
 644 JRT_END
 645 
 646 JRT_ENTRY(void, InterpreterRuntime::throw_NullPointerException(JavaThread* current))
 647   THROW(vmSymbols::java_lang_NullPointerException());

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




 709     if ((is_put && !has_initialized_final_update) || !info.access_flags().is_final()) {
 710       put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
 711     }
 712   }
 713 
 714   ResolvedFieldEntry* entry = pool->resolved_field_entry_at(field_index);
 715   entry->set_flags(info.access_flags().is_final(), info.access_flags().is_volatile());

 716   entry->fill_in(info.field_holder(), info.offset(),
 717                  checked_cast<u2>(info.index()), checked_cast<u1>(state),
 718                  static_cast<u1>(get_code), static_cast<u1>(put_code));
 719 }
 720 
 721 
 722 //------------------------------------------------------------------------------------------------------------------------
 723 // Synchronization
 724 //
 725 // The interpreter's synchronization code is factored out so that it can
 726 // be shared by method invocation and synchronized blocks.
 727 //%note synchronization_3
 728 
 729 //%note monitor_1
 730 JRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* current, BasicObjectLock* elem))
 731   assert(LockingMode != LM_LIGHTWEIGHT, "Should call monitorenter_obj() when using the new lightweight locking");
 732 #ifdef ASSERT
 733   current->last_frame().interpreter_frame_verify_monitor(elem);
 734 #endif
 735   Handle h_obj(current, elem->obj());

1139     LastFrameAccessor last_frame(current);
1140     JvmtiExport::at_single_stepping_point(current, last_frame.method(), last_frame.bcp());
1141   }
1142 JRT_END
1143 
1144 JRT_LEAF(void, InterpreterRuntime::at_unwind(JavaThread* current))
1145   assert(current == JavaThread::current(), "pre-condition");
1146   // This function is called by the interpreter when the return poll found a reason
1147   // to call the VM. The reason could be that we are returning into a not yet safe
1148   // to access frame. We handle that below.
1149   // Note that this path does not check for single stepping, because we do not want
1150   // to single step when unwinding frames for an exception being thrown. Instead,
1151   // such single stepping code will use the safepoint table, which will use the
1152   // InterpreterRuntime::at_safepoint callback.
1153   StackWatermarkSet::before_unwind(current);
1154 JRT_END
1155 
1156 JRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread* current, oopDesc* obj,
1157                                                       ResolvedFieldEntry *entry))
1158 

1159   // check the access_flags for the field in the klass
1160 
1161   InstanceKlass* ik = entry->field_holder();
1162   int index = entry->field_index();
1163   if (!ik->field_status(index).is_access_watched()) return;
1164 
1165   bool is_static = (obj == nullptr);

1166   HandleMark hm(current);
1167 
1168   Handle h_obj;
1169   if (!is_static) {
1170     // non-static field accessors have an object, but we need a handle
1171     h_obj = Handle(current, obj);
1172   }
1173   InstanceKlass* field_holder = entry->field_holder(); // HERE
1174   jfieldID fid = jfieldIDWorkaround::to_jfieldID(field_holder, entry->field_offset(), is_static);
1175   LastFrameAccessor last_frame(current);
1176   JvmtiExport::post_field_access(current, last_frame.method(), last_frame.bcp(), field_holder, h_obj, fid);
1177 JRT_END
1178 
1179 JRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread* current, oopDesc* obj,
1180                                                             ResolvedFieldEntry *entry, jvalue *value))
1181 

1182   InstanceKlass* ik = entry->field_holder();
1183 
1184   // check the access_flags for the field in the klass
1185   int index = entry->field_index();
1186   // bail out if field modifications are not watched
1187   if (!ik->field_status(index).is_modification_watched()) return;
1188 
1189   char sig_type = '\0';
1190 
1191   switch((TosState)entry->tos_state()) {
1192     case btos: sig_type = JVM_SIGNATURE_BYTE;    break;
1193     case ztos: sig_type = JVM_SIGNATURE_BOOLEAN; break;
1194     case ctos: sig_type = JVM_SIGNATURE_CHAR;    break;
1195     case stos: sig_type = JVM_SIGNATURE_SHORT;   break;
1196     case itos: sig_type = JVM_SIGNATURE_INT;     break;
1197     case ftos: sig_type = JVM_SIGNATURE_FLOAT;   break;
1198     case atos: sig_type = JVM_SIGNATURE_CLASS;   break;
1199     case ltos: sig_type = JVM_SIGNATURE_LONG;    break;
1200     case dtos: sig_type = JVM_SIGNATURE_DOUBLE;  break;
1201     default:  ShouldNotReachHere(); return;
1202   }

1203   bool is_static = (obj == nullptr);

1204 
1205   HandleMark hm(current);
1206   jfieldID fid = jfieldIDWorkaround::to_jfieldID(ik, entry->field_offset(), is_static);
1207   jvalue fvalue;
1208 #ifdef _LP64
1209   fvalue = *value;
1210 #else
1211   // Long/double values are stored unaligned and also noncontiguously with
1212   // tagged stacks.  We can't just do a simple assignment even in the non-
1213   // J/D cases because a C++ compiler is allowed to assume that a jvalue is
1214   // 8-byte aligned, and interpreter stack slots are only 4-byte aligned.
1215   // We assume that the two halves of longs/doubles are stored in interpreter
1216   // stack slots in platform-endian order.
1217   jlong_accessor u;
1218   jint* newval = (jint*)value;
1219   u.words[0] = newval[0];
1220   u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
1221   fvalue.j = u.long_value;
1222 #endif // _LP64
1223 
1224   Handle h_obj;
1225   if (!is_static) {
1226     // non-static field accessors have an object, but we need a handle

   8  *
   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 "classfile/javaClasses.inline.hpp"
  27 #include "classfile/symbolTable.hpp"
  28 #include "classfile/systemDictionary.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/bytecodeTracer.hpp"
  38 #include "interpreter/interpreter.hpp"
  39 #include "interpreter/interpreterRuntime.hpp"
  40 #include "interpreter/linkResolver.hpp"
  41 #include "interpreter/templateTable.hpp"
  42 #include "jvm_io.h"
  43 #include "logging/log.hpp"
  44 #include "memory/oopFactory.hpp"
  45 #include "memory/resourceArea.hpp"
  46 #include "memory/universe.hpp"
  47 #include "oops/constantPool.inline.hpp"
  48 #include "oops/cpCache.inline.hpp"
  49 #include "oops/flatArrayKlass.hpp"
  50 #include "oops/flatArrayOop.inline.hpp"
  51 #include "oops/inlineKlass.inline.hpp"
  52 #include "oops/instanceKlass.inline.hpp"
  53 #include "oops/klass.inline.hpp"
  54 #include "oops/methodData.hpp"
  55 #include "oops/method.inline.hpp"
  56 #include "oops/objArrayKlass.hpp"
  57 #include "oops/objArrayOop.inline.hpp"
  58 #include "oops/oop.inline.hpp"
  59 #include "oops/symbol.hpp"
  60 #include "prims/jvmtiExport.hpp"
  61 #include "prims/methodHandles.hpp"
  62 #include "prims/nativeLookup.hpp"
  63 #include "runtime/atomic.hpp"
  64 #include "runtime/continuation.hpp"
  65 #include "runtime/deoptimization.hpp"
  66 #include "runtime/fieldDescriptor.inline.hpp"
  67 #include "runtime/frame.inline.hpp"
  68 #include "runtime/handles.inline.hpp"
  69 #include "runtime/icache.hpp"
  70 #include "runtime/interfaceSupport.inline.hpp"
  71 #include "runtime/java.hpp"
  72 #include "runtime/javaCalls.hpp"
  73 #include "runtime/jfieldIDWorkaround.hpp"
  74 #include "runtime/osThread.hpp"
  75 #include "runtime/sharedRuntime.hpp"
  76 #include "runtime/stackWatermarkSet.hpp"
  77 #include "runtime/stubRoutines.hpp"
  78 #include "runtime/synchronizer.hpp"
  79 #include "runtime/threadCritical.hpp"
  80 #include "utilities/align.hpp"
  81 #include "utilities/checkedCast.hpp"
  82 #include "utilities/copy.hpp"
  83 #include "utilities/events.hpp"
  84 #include "utilities/globalDefinitions.hpp"
  85 #ifdef COMPILER2
  86 #include "opto/runtime.hpp"
  87 #endif
  88 
  89 // Helper class to access current interpreter state
  90 class LastFrameAccessor : public StackObj {
  91   frame _last_frame;
  92 public:
  93   LastFrameAccessor(JavaThread* current) {
  94     assert(current == Thread::current(), "sanity");
  95     _last_frame = current->last_frame();
  96   }
  97   bool is_interpreted_frame() const              { return _last_frame.is_interpreted_frame(); }
  98   Method*   method() const                       { return _last_frame.interpreter_frame_method(); }
  99   address   bcp() const                          { return _last_frame.interpreter_frame_bcp(); }
 100   int       bci() const                          { return _last_frame.interpreter_frame_bci(); }
 101   address   mdp() const                          { return _last_frame.interpreter_frame_mdp(); }
 102 
 103   void      set_bcp(address bcp)                 { _last_frame.interpreter_frame_set_bcp(bcp); }
 104   void      set_mdp(address dp)                  { _last_frame.interpreter_frame_set_mdp(dp); }

 229   klass->initialize(CHECK);
 230 
 231   // At this point the class may not be fully initialized
 232   // because of recursive initialization. If it is fully
 233   // initialized & has_finalized is not set, we rewrite
 234   // it into its fast version (Note: no locking is needed
 235   // here since this is an atomic byte write and can be
 236   // done more than once).
 237   //
 238   // Note: In case of classes with has_finalized we don't
 239   //       rewrite since that saves us an extra check in
 240   //       the fast version which then would call the
 241   //       slow version anyway (and do a call back into
 242   //       Java).
 243   //       If we have a breakpoint, then we don't rewrite
 244   //       because the _breakpoint bytecode would be lost.
 245   oop obj = klass->allocate_instance(CHECK);
 246   current->set_vm_result(obj);
 247 JRT_END
 248 
 249 JRT_ENTRY(void, InterpreterRuntime::uninitialized_static_inline_type_field(JavaThread* current, oopDesc* mirror, ResolvedFieldEntry* entry))
 250   // The interpreter tries to access an inline static field that has not been initialized.
 251   // This situation can happen in different scenarios:
 252   //   1 - if the load or initialization of the field failed during step 8 of
 253   //       the initialization of the holder of the field, in this case the access to the field
 254   //       must fail
 255   //   2 - it can also happen when the initialization of the holder class triggered the initialization of
 256   //       another class which accesses this field in its static initializer, in this case the
 257   //       access must succeed to allow circularity
 258   // The code below tries to load and initialize the field's class again before returning the default value.
 259   // If the field was not initialized because of an error, an exception should be thrown.
 260   // If the class is being initialized, the default value is returned.
 261   assert(entry->is_valid(), "Invalid ResolvedFieldEntry");
 262   instanceHandle mirror_h(THREAD, (instanceOop)mirror);
 263   InstanceKlass* klass = entry->field_holder();
 264   u2 index = entry->field_index();
 265   assert(klass == java_lang_Class::as_Klass(mirror), "Not the field holder klass");
 266   assert(klass->field_is_null_free_inline_type(index), "Sanity check");
 267   if (klass->is_being_initialized() && klass->is_init_thread(THREAD)) {
 268     int offset = klass->field_offset(index);
 269     Klass* field_k = klass->get_inline_type_field_klass_or_null(index);
 270     if (field_k == nullptr) {
 271       field_k = SystemDictionary::resolve_or_fail(klass->field_signature(index)->fundamental_name(THREAD),
 272           Handle(THREAD, klass->class_loader()),
 273           Handle(THREAD, klass->protection_domain()),
 274           true, CHECK);
 275       assert(field_k != nullptr, "Should have been loaded or an exception thrown above");
 276       klass->set_inline_type_field_klass(index, InlineKlass::cast(field_k));
 277     }
 278     field_k->initialize(CHECK);
 279     oop defaultvalue = InlineKlass::cast(field_k)->default_value();
 280     // It is safe to initialize the static field because 1) the current thread is the initializing thread
 281     // and is the only one that can access it, and 2) the field is actually not initialized (i.e. null)
 282     // otherwise the JVM should not be executing this code.
 283     mirror_h()->obj_field_put(offset, defaultvalue);
 284     current->set_vm_result(defaultvalue);
 285   } else {
 286     assert(klass->is_in_error_state(), "If not initializing, initialization must have failed to get there");
 287     ResourceMark rm(THREAD);
 288     const char* desc = "Could not initialize class ";
 289     const char* className = klass->external_name();
 290     size_t msglen = strlen(desc) + strlen(className) + 1;
 291     char* message = NEW_RESOURCE_ARRAY(char, msglen);
 292     if (nullptr == message) {
 293       // Out of memory: can't create detailed error message
 294       THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), className);
 295     } else {
 296       jio_snprintf(message, msglen, "%s%s", desc, className);
 297       THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), message);
 298     }
 299   }
 300 JRT_END
 301 
 302 JRT_ENTRY(void, InterpreterRuntime::read_flat_field(JavaThread* current, oopDesc* obj, int index, Klass* field_holder))
 303   Handle obj_h(THREAD, obj);
 304 
 305   assert(oopDesc::is_oop(obj), "Sanity check");
 306 
 307   assert(field_holder->is_instance_klass(), "Sanity check");
 308   InstanceKlass* klass = InstanceKlass::cast(field_holder);
 309 
 310   assert(klass->field_is_flat(index), "Sanity check");
 311 
 312   InlineKlass* field_vklass = InlineKlass::cast(klass->get_inline_type_field_klass(index));
 313 
 314   oop res = field_vklass->read_flat_field(obj_h(), klass->field_offset(index), CHECK);
 315   current->set_vm_result(res);
 316 JRT_END
 317 
 318 JRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* current, BasicType type, jint size))
 319   oop obj = oopFactory::new_typeArray(type, size, CHECK);
 320   current->set_vm_result(obj);
 321 JRT_END
 322 
 323 
 324 JRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* current, ConstantPool* pool, int index, jint size))
 325   Klass*    klass = pool->klass_at(index, CHECK);
 326   arrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
 327   current->set_vm_result(obj);
 328 JRT_END
 329 
 330 JRT_ENTRY(void, InterpreterRuntime::value_array_load(JavaThread* current, arrayOopDesc* array, int index))
 331   flatArrayHandle vah(current, (flatArrayOop)array);
 332   oop value_holder = flatArrayOopDesc::value_alloc_copy_from_index(vah, index, CHECK);
 333   current->set_vm_result(value_holder);
 334 JRT_END
 335 
 336 JRT_ENTRY(void, InterpreterRuntime::value_array_store(JavaThread* current, void* val, arrayOopDesc* array, int index))
 337   assert(val != nullptr, "can't store null into flat array");
 338   ((flatArrayOop)array)->value_copy_to_index(cast_to_oop(val), index);
 339 JRT_END
 340 
 341 JRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* current, jint* first_size_address))
 342   // We may want to pass in more arguments - could make this slightly faster
 343   LastFrameAccessor last_frame(current);
 344   ConstantPool* constants = last_frame.method()->constants();
 345   int i = last_frame.get_index_u2(Bytecodes::_multianewarray);
 346   Klass* klass = constants->klass_at(i, CHECK);
 347   int   nof_dims = last_frame.number_of_dimensions();
 348   assert(klass->is_klass(), "not a class");
 349   assert(nof_dims >= 1, "multianewarray rank must be nonzero");
 350 
 351   // We must create an array of jints to pass to multi_allocate.
 352   ResourceMark rm(current);
 353   const int small_dims = 10;
 354   jint dim_array[small_dims];
 355   jint *dims = &dim_array[0];
 356   if (nof_dims > small_dims) {
 357     dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
 358   }
 359   for (int index = 0; index < nof_dims; index++) {
 360     // offset from first_size_address is addressed as local[index]
 361     int n = Interpreter::local_offset_in_bytes(index)/jintSize;
 362     dims[index] = first_size_address[n];
 363   }
 364   oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
 365   current->set_vm_result(obj);
 366 JRT_END
 367 
 368 
 369 JRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* current, oopDesc* obj))
 370   assert(oopDesc::is_oop(obj), "must be a valid oop");
 371   assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
 372   InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
 373 JRT_END
 374 
 375 JRT_ENTRY(jboolean, InterpreterRuntime::is_substitutable(JavaThread* current, oopDesc* aobj, oopDesc* bobj))
 376   assert(oopDesc::is_oop(aobj) && oopDesc::is_oop(bobj), "must be valid oops");
 377 
 378   Handle ha(THREAD, aobj);
 379   Handle hb(THREAD, bobj);
 380   JavaValue result(T_BOOLEAN);
 381   JavaCallArguments args;
 382   args.push_oop(ha);
 383   args.push_oop(hb);
 384   methodHandle method(current, Universe::is_substitutable_method());
 385   JavaCalls::call(&result, method, &args, THREAD);
 386   if (HAS_PENDING_EXCEPTION) {
 387     // Something really bad happened because isSubstitutable() should not throw exceptions
 388     // If it is an error, just let it propagate
 389     // If it is an exception, wrap it into an InternalError
 390     if (!PENDING_EXCEPTION->is_a(vmClasses::Error_klass())) {
 391       Handle e(THREAD, PENDING_EXCEPTION);
 392       CLEAR_PENDING_EXCEPTION;
 393       THROW_MSG_CAUSE_(vmSymbols::java_lang_InternalError(), "Internal error in substitutability test", e, false);
 394     }
 395   }
 396   return result.get_jboolean();
 397 JRT_END
 398 
 399 // Quicken instance-of and check-cast bytecodes
 400 JRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* current))
 401   // Force resolving; quicken the bytecode
 402   LastFrameAccessor last_frame(current);
 403   int which = last_frame.get_index_u2(Bytecodes::_checkcast);
 404   ConstantPool* cpool = last_frame.method()->constants();
 405   // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
 406   // program we might have seen an unquick'd bytecode in the interpreter but have another
 407   // thread quicken the bytecode before we get here.
 408   // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
 409   Klass* klass = cpool->klass_at(which, CHECK);
 410   current->set_vm_result_2(klass);
 411 JRT_END
 412 
 413 
 414 //------------------------------------------------------------------------------------------------------------------------
 415 // Exceptions
 416 
 417 void InterpreterRuntime::note_trap_inner(JavaThread* current, int reason,

 714 // and therefore we don't have the receiver object at our fingertips. (Though,
 715 // on some platforms the receiver still resides in a register...). Thus,
 716 // we have no choice but print an error message not containing the receiver
 717 // type.
 718 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorWithMethod(JavaThread* current,
 719                                                                         Method* missingMethod))
 720   ResourceMark rm(current);
 721   assert(missingMethod != nullptr, "sanity");
 722   methodHandle m(current, missingMethod);
 723   LinkResolver::throw_abstract_method_error(m, THREAD);
 724 JRT_END
 725 
 726 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorVerbose(JavaThread* current,
 727                                                                      Klass* recvKlass,
 728                                                                      Method* missingMethod))
 729   ResourceMark rm(current);
 730   methodHandle mh = methodHandle(current, missingMethod);
 731   LinkResolver::throw_abstract_method_error(mh, recvKlass, THREAD);
 732 JRT_END
 733 
 734 JRT_ENTRY(void, InterpreterRuntime::throw_InstantiationError(JavaThread* current))
 735   THROW(vmSymbols::java_lang_InstantiationError());
 736 JRT_END
 737 
 738 
 739 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* current))
 740   THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
 741 JRT_END
 742 
 743 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose(JavaThread* current,
 744                                                                               Klass* recvKlass,
 745                                                                               Klass* interfaceKlass))
 746   ResourceMark rm(current);
 747   char buf[1000];
 748   buf[0] = '\0';
 749   jio_snprintf(buf, sizeof(buf),
 750                "Class %s does not implement the requested interface %s",
 751                recvKlass ? recvKlass->external_name() : "nullptr",
 752                interfaceKlass ? interfaceKlass->external_name() : "nullptr");
 753   THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
 754 JRT_END
 755 
 756 JRT_ENTRY(void, InterpreterRuntime::throw_NullPointerException(JavaThread* current))
 757   THROW(vmSymbols::java_lang_NullPointerException());

 798   // initializer method <init>. If resolution were not inhibited, a putfield
 799   // in an initializer method could be resolved in the initializer. Subsequent
 800   // putfield instructions to the same field would then use cached information.
 801   // As a result, those instructions would not pass through the VM. That is,
 802   // checks in resolve_field_access() would not be executed for those instructions
 803   // and the required IllegalAccessError would not be thrown.
 804   //
 805   // Also, we need to delay resolving getstatic and putstatic instructions until the
 806   // class is initialized.  This is required so that access to the static
 807   // field will call the initialization function every time until the class
 808   // is completely initialized ala. in 2.17.5 in JVM Specification.
 809   InstanceKlass* klass = info.field_holder();
 810   bool uninitialized_static = is_static && !klass->is_initialized();
 811   bool has_initialized_final_update = info.field_holder()->major_version() >= 53 &&
 812                                       info.has_initialized_final_update();
 813   assert(!(has_initialized_final_update && !info.access_flags().is_final()), "Fields with initialized final updates must be final");
 814 
 815   Bytecodes::Code get_code = (Bytecodes::Code)0;
 816   Bytecodes::Code put_code = (Bytecodes::Code)0;
 817   if (!uninitialized_static) {
 818     if (is_static) {
 819       get_code = Bytecodes::_getstatic;
 820     } else {
 821       get_code = Bytecodes::_getfield;
 822     }
 823     if ((is_put && !has_initialized_final_update) || !info.access_flags().is_final()) {
 824         put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
 825     }
 826   }
 827 
 828   ResolvedFieldEntry* entry = pool->resolved_field_entry_at(field_index);
 829   entry->set_flags(info.access_flags().is_final(), info.access_flags().is_volatile(),
 830                    info.is_flat(), info.is_null_free_inline_type());
 831   entry->fill_in(info.field_holder(), info.offset(),
 832                  checked_cast<u2>(info.index()), checked_cast<u1>(state),
 833                  static_cast<u1>(get_code), static_cast<u1>(put_code));
 834 }
 835 
 836 
 837 //------------------------------------------------------------------------------------------------------------------------
 838 // Synchronization
 839 //
 840 // The interpreter's synchronization code is factored out so that it can
 841 // be shared by method invocation and synchronized blocks.
 842 //%note synchronization_3
 843 
 844 //%note monitor_1
 845 JRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* current, BasicObjectLock* elem))
 846   assert(LockingMode != LM_LIGHTWEIGHT, "Should call monitorenter_obj() when using the new lightweight locking");
 847 #ifdef ASSERT
 848   current->last_frame().interpreter_frame_verify_monitor(elem);
 849 #endif
 850   Handle h_obj(current, elem->obj());

1254     LastFrameAccessor last_frame(current);
1255     JvmtiExport::at_single_stepping_point(current, last_frame.method(), last_frame.bcp());
1256   }
1257 JRT_END
1258 
1259 JRT_LEAF(void, InterpreterRuntime::at_unwind(JavaThread* current))
1260   assert(current == JavaThread::current(), "pre-condition");
1261   // This function is called by the interpreter when the return poll found a reason
1262   // to call the VM. The reason could be that we are returning into a not yet safe
1263   // to access frame. We handle that below.
1264   // Note that this path does not check for single stepping, because we do not want
1265   // to single step when unwinding frames for an exception being thrown. Instead,
1266   // such single stepping code will use the safepoint table, which will use the
1267   // InterpreterRuntime::at_safepoint callback.
1268   StackWatermarkSet::before_unwind(current);
1269 JRT_END
1270 
1271 JRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread* current, oopDesc* obj,
1272                                                       ResolvedFieldEntry *entry))
1273 
1274   assert(entry->is_valid(), "Invalid ResolvedFieldEntry");
1275   // check the access_flags for the field in the klass
1276 
1277   InstanceKlass* ik = entry->field_holder();
1278   int index = entry->field_index();
1279   if (!ik->field_status(index).is_access_watched()) return;
1280 
1281   bool is_static = (obj == nullptr);
1282   bool is_flat = entry->is_flat();
1283   HandleMark hm(current);
1284 
1285   Handle h_obj;
1286   if (!is_static) {
1287     // non-static field accessors have an object, but we need a handle
1288     h_obj = Handle(current, obj);
1289   }
1290   InstanceKlass* field_holder = entry->field_holder(); // HERE
1291   jfieldID fid = jfieldIDWorkaround::to_jfieldID(field_holder, entry->field_offset(), is_static, is_flat);
1292   LastFrameAccessor last_frame(current);
1293   JvmtiExport::post_field_access(current, last_frame.method(), last_frame.bcp(), field_holder, h_obj, fid);
1294 JRT_END
1295 
1296 JRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread* current, oopDesc* obj,
1297                                                             ResolvedFieldEntry *entry, jvalue *value))
1298 
1299   assert(entry->is_valid(), "Invalid ResolvedFieldEntry");
1300   InstanceKlass* ik = entry->field_holder();
1301 
1302   // check the access_flags for the field in the klass
1303   int index = entry->field_index();
1304   // bail out if field modifications are not watched
1305   if (!ik->field_status(index).is_modification_watched()) return;
1306 
1307   char sig_type = '\0';
1308 
1309   switch((TosState)entry->tos_state()) {
1310     case btos: sig_type = JVM_SIGNATURE_BYTE;    break;
1311     case ztos: sig_type = JVM_SIGNATURE_BOOLEAN; break;
1312     case ctos: sig_type = JVM_SIGNATURE_CHAR;    break;
1313     case stos: sig_type = JVM_SIGNATURE_SHORT;   break;
1314     case itos: sig_type = JVM_SIGNATURE_INT;     break;
1315     case ftos: sig_type = JVM_SIGNATURE_FLOAT;   break;
1316     case atos: sig_type = JVM_SIGNATURE_CLASS;   break;
1317     case ltos: sig_type = JVM_SIGNATURE_LONG;    break;
1318     case dtos: sig_type = JVM_SIGNATURE_DOUBLE;  break;
1319     default:  ShouldNotReachHere(); return;
1320   }
1321 
1322   bool is_static = (obj == nullptr);
1323   bool is_flat = entry->is_flat();
1324 
1325   HandleMark hm(current);
1326   jfieldID fid = jfieldIDWorkaround::to_jfieldID(ik, entry->field_offset(), is_static, is_flat);
1327   jvalue fvalue;
1328 #ifdef _LP64
1329   fvalue = *value;
1330 #else
1331   // Long/double values are stored unaligned and also noncontiguously with
1332   // tagged stacks.  We can't just do a simple assignment even in the non-
1333   // J/D cases because a C++ compiler is allowed to assume that a jvalue is
1334   // 8-byte aligned, and interpreter stack slots are only 4-byte aligned.
1335   // We assume that the two halves of longs/doubles are stored in interpreter
1336   // stack slots in platform-endian order.
1337   jlong_accessor u;
1338   jint* newval = (jint*)value;
1339   u.words[0] = newval[0];
1340   u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
1341   fvalue.j = u.long_value;
1342 #endif // _LP64
1343 
1344   Handle h_obj;
1345   if (!is_static) {
1346     // non-static field accessors have an object, but we need a handle
< prev index next >