< prev index next >

src/hotspot/share/interpreter/interpreterRuntime.cpp

Print this page

   7  * published by the Free Software Foundation.
   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 "classfile/javaClasses.inline.hpp"
  26 #include "classfile/symbolTable.hpp"

  27 #include "classfile/vmClasses.hpp"
  28 #include "classfile/vmSymbols.hpp"
  29 #include "code/codeCache.hpp"
  30 #include "compiler/compilationPolicy.hpp"
  31 #include "compiler/compileBroker.hpp"
  32 #include "compiler/disassembler.hpp"
  33 #include "gc/shared/barrierSetNMethod.hpp"
  34 #include "gc/shared/collectedHeap.hpp"
  35 #include "interpreter/bytecodeTracer.hpp"
  36 #include "interpreter/interpreter.hpp"
  37 #include "interpreter/interpreterRuntime.hpp"
  38 #include "interpreter/linkResolver.hpp"
  39 #include "interpreter/templateTable.hpp"
  40 #include "jvm_io.h"
  41 #include "logging/log.hpp"
  42 #include "memory/oopFactory.hpp"
  43 #include "memory/resourceArea.hpp"
  44 #include "memory/universe.hpp"
  45 #include "oops/constantPool.inline.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/method.inline.hpp"
  51 #include "oops/objArrayKlass.hpp"
  52 #include "oops/objArrayOop.inline.hpp"
  53 #include "oops/oop.inline.hpp"
  54 #include "oops/symbol.hpp"
  55 #include "prims/jvmtiExport.hpp"
  56 #include "prims/methodHandles.hpp"
  57 #include "prims/nativeLookup.hpp"
  58 #include "runtime/atomic.hpp"
  59 #include "runtime/continuation.hpp"
  60 #include "runtime/deoptimization.hpp"
  61 #include "runtime/fieldDescriptor.inline.hpp"
  62 #include "runtime/frame.inline.hpp"
  63 #include "runtime/handles.inline.hpp"
  64 #include "runtime/icache.hpp"
  65 #include "runtime/interfaceSupport.inline.hpp"
  66 #include "runtime/java.hpp"
  67 #include "runtime/javaCalls.hpp"
  68 #include "runtime/jfieldIDWorkaround.hpp"
  69 #include "runtime/osThread.hpp"
  70 #include "runtime/sharedRuntime.hpp"
  71 #include "runtime/stackWatermarkSet.hpp"
  72 #include "runtime/stubRoutines.hpp"
  73 #include "runtime/synchronizer.inline.hpp"
  74 #include "runtime/threadCritical.hpp"
  75 #include "utilities/align.hpp"
  76 #include "utilities/checkedCast.hpp"
  77 #include "utilities/copy.hpp"
  78 #include "utilities/events.hpp"

  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); }
  96 
  97   // pass method to avoid calling unsafe bcp_to_method (partial fix 4926272)
  98   Bytecodes::Code code() const                   { return Bytecodes::code_at(method(), bcp()); }

 206 JRT_END
 207 
 208 
 209 //------------------------------------------------------------------------------------------------------------------------
 210 // Allocation
 211 
 212 JRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* current, ConstantPool* pool, int index))
 213   Klass* k = pool->klass_at(index, CHECK);
 214   InstanceKlass* klass = InstanceKlass::cast(k);
 215 
 216   // Make sure we are not instantiating an abstract klass
 217   klass->check_valid_for_instantiation(true, CHECK);
 218 
 219   // Make sure klass is initialized
 220   klass->initialize(CHECK);
 221 
 222   oop obj = klass->allocate_instance(CHECK);
 223   current->set_vm_result(obj);
 224 JRT_END
 225 

















































































































 226 
 227 JRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* current, BasicType type, jint size))
 228   oop obj = oopFactory::new_typeArray(type, size, CHECK);
 229   current->set_vm_result(obj);
 230 JRT_END
 231 
 232 
 233 JRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* current, ConstantPool* pool, int index, jint size))
 234   Klass*    klass = pool->klass_at(index, CHECK);
 235   objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
 236   current->set_vm_result(obj);
 237 JRT_END
 238 












 239 
 240 JRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* current, jint* first_size_address))
 241   // We may want to pass in more arguments - could make this slightly faster
 242   LastFrameAccessor last_frame(current);
 243   ConstantPool* constants = last_frame.method()->constants();
 244   int          i = last_frame.get_index_u2(Bytecodes::_multianewarray);
 245   Klass* klass   = constants->klass_at(i, CHECK);
 246   int   nof_dims = last_frame.number_of_dimensions();
 247   assert(klass->is_klass(), "not a class");
 248   assert(nof_dims >= 1, "multianewarray rank must be nonzero");
 249 
 250   // We must create an array of jints to pass to multi_allocate.
 251   ResourceMark rm(current);
 252   const int small_dims = 10;
 253   jint dim_array[small_dims];
 254   jint *dims = &dim_array[0];
 255   if (nof_dims > small_dims) {
 256     dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
 257   }
 258   for (int index = 0; index < nof_dims; index++) {
 259     // offset from first_size_address is addressed as local[index]
 260     int n = Interpreter::local_offset_in_bytes(index)/jintSize;
 261     dims[index] = first_size_address[n];
 262   }
 263   oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
 264   current->set_vm_result(obj);
 265 JRT_END
 266 
 267 
 268 JRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* current, oopDesc* obj))
 269   assert(oopDesc::is_oop(obj), "must be a valid oop");
 270   assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
 271   InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
 272 JRT_END
 273 
























 274 
 275 // Quicken instance-of and check-cast bytecodes
 276 JRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* current))
 277   // Force resolving; quicken the bytecode
 278   LastFrameAccessor last_frame(current);
 279   int which = last_frame.get_index_u2(Bytecodes::_checkcast);
 280   ConstantPool* cpool = last_frame.method()->constants();
 281   // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
 282   // program we might have seen an unquick'd bytecode in the interpreter but have another
 283   // thread quicken the bytecode before we get here.
 284   // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
 285   Klass* klass = cpool->klass_at(which, CHECK);
 286   current->set_vm_result_2(klass);
 287 JRT_END
 288 
 289 
 290 //------------------------------------------------------------------------------------------------------------------------
 291 // Exceptions
 292 
 293 void InterpreterRuntime::note_trap_inner(JavaThread* current, int reason,

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




 617 
 618 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* current))
 619   THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
 620 JRT_END
 621 
 622 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose(JavaThread* current,
 623                                                                               Klass* recvKlass,
 624                                                                               Klass* interfaceKlass))
 625   ResourceMark rm(current);
 626   char buf[1000];
 627   buf[0] = '\0';
 628   jio_snprintf(buf, sizeof(buf),
 629                "Class %s does not implement the requested interface %s",
 630                recvKlass ? recvKlass->external_name() : "nullptr",
 631                interfaceKlass ? interfaceKlass->external_name() : "nullptr");
 632   THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
 633 JRT_END
 634 
 635 JRT_ENTRY(void, InterpreterRuntime::throw_NullPointerException(JavaThread* current))
 636   THROW(vmSymbols::java_lang_NullPointerException());

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




 702     if ((is_put && !has_initialized_final_update) || !info.access_flags().is_final()) {
 703       put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
 704     }
 705   }
 706 
 707   ResolvedFieldEntry* entry = pool->resolved_field_entry_at(field_index);
 708   entry->set_flags(info.access_flags().is_final(), info.access_flags().is_volatile());



 709   entry->fill_in(info.field_holder(), info.offset(),
 710                  checked_cast<u2>(info.index()), checked_cast<u1>(state),
 711                  static_cast<u1>(get_code), static_cast<u1>(put_code));
 712 }
 713 
 714 
 715 //------------------------------------------------------------------------------------------------------------------------
 716 // Synchronization
 717 //
 718 // The interpreter's synchronization code is factored out so that it can
 719 // be shared by method invocation and synchronized blocks.
 720 //%note synchronization_3
 721 
 722 //%note monitor_1
 723 JRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* current, BasicObjectLock* elem))
 724 #ifdef ASSERT
 725   current->last_frame().interpreter_frame_verify_monitor(elem);
 726 #endif
 727   Handle h_obj(current, elem->obj());
 728   assert(Universe::heap()->is_in_or_null(h_obj()),

 735 #endif
 736 JRT_END
 737 
 738 JRT_LEAF(void, InterpreterRuntime::monitorexit(BasicObjectLock* elem))
 739   oop obj = elem->obj();
 740   assert(Universe::heap()->is_in(obj), "must be an object");
 741   // The object could become unlocked through a JNI call, which we have no other checks for.
 742   // Give a fatal message if CheckJNICalls. Otherwise we ignore it.
 743   if (obj->is_unlocked()) {
 744     if (CheckJNICalls) {
 745       fatal("Object has been unlocked by JNI");
 746     }
 747     return;
 748   }
 749   ObjectSynchronizer::exit(obj, elem->lock(), JavaThread::current());
 750   // Free entry. If it is not cleared, the exception handling code will try to unlock the monitor
 751   // again at method exit or in the case of an exception.
 752   elem->set_obj(nullptr);
 753 JRT_END
 754 
 755 
 756 JRT_ENTRY(void, InterpreterRuntime::throw_illegal_monitor_state_exception(JavaThread* current))
 757   THROW(vmSymbols::java_lang_IllegalMonitorStateException());
 758 JRT_END
 759 
 760 
 761 JRT_ENTRY(void, InterpreterRuntime::new_illegal_monitor_state_exception(JavaThread* current))
 762   // Returns an illegal exception to install into the current thread. The
 763   // pending_exception flag is cleared so normal exception handling does not
 764   // trigger. Any current installed exception will be overwritten. This
 765   // method will be called during an exception unwind.
 766 
 767   assert(!HAS_PENDING_EXCEPTION, "no pending exception");
 768   Handle exception(current, current->vm_result());
 769   assert(exception() != nullptr, "vm result should be set");
 770   current->set_vm_result(nullptr); // clear vm result before continuing (may cause memory leaks and assert failures)
 771   exception = get_preinitialized_exception(vmClasses::IllegalMonitorStateException_klass(), CATCH);
 772   current->set_vm_result(exception());
 773 JRT_END
 774 















 775 
 776 //------------------------------------------------------------------------------------------------------------------------
 777 // Invokes
 778 
 779 JRT_ENTRY(Bytecodes::Code, InterpreterRuntime::get_original_bytecode_at(JavaThread* current, Method* method, address bcp))
 780   return method->orig_bytecode_at(method->bci_from(bcp));
 781 JRT_END
 782 
 783 JRT_ENTRY(void, InterpreterRuntime::set_original_bytecode_at(JavaThread* current, Method* method, address bcp, Bytecodes::Code new_code))
 784   method->set_orig_bytecode_at(method->bci_from(bcp), new_code);
 785 JRT_END
 786 
 787 JRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* current, Method* method, address bcp))
 788   JvmtiExport::post_raw_breakpoint(current, method, bcp);
 789 JRT_END
 790 
 791 void InterpreterRuntime::resolve_invoke(JavaThread* current, Bytecodes::Code bytecode) {
 792   LastFrameAccessor last_frame(current);
 793   // extract receiver from the outgoing argument list if necessary
 794   Handle receiver(current, nullptr);

1164     LastFrameAccessor last_frame(current);
1165     JvmtiExport::at_single_stepping_point(current, last_frame.method(), last_frame.bcp());
1166   }
1167 JRT_END
1168 
1169 JRT_LEAF(void, InterpreterRuntime::at_unwind(JavaThread* current))
1170   assert(current == JavaThread::current(), "pre-condition");
1171   // This function is called by the interpreter when the return poll found a reason
1172   // to call the VM. The reason could be that we are returning into a not yet safe
1173   // to access frame. We handle that below.
1174   // Note that this path does not check for single stepping, because we do not want
1175   // to single step when unwinding frames for an exception being thrown. Instead,
1176   // such single stepping code will use the safepoint table, which will use the
1177   // InterpreterRuntime::at_safepoint callback.
1178   StackWatermarkSet::before_unwind(current);
1179 JRT_END
1180 
1181 JRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread* current, oopDesc* obj,
1182                                                       ResolvedFieldEntry *entry))
1183 

1184   // check the access_flags for the field in the klass
1185 
1186   InstanceKlass* ik = entry->field_holder();
1187   int index = entry->field_index();
1188   if (!ik->field_status(index).is_access_watched()) return;
1189 
1190   bool is_static = (obj == nullptr);

1191   HandleMark hm(current);
1192 
1193   Handle h_obj;
1194   if (!is_static) {
1195     // non-static field accessors have an object, but we need a handle
1196     h_obj = Handle(current, obj);
1197   }
1198   InstanceKlass* field_holder = entry->field_holder(); // HERE
1199   jfieldID fid = jfieldIDWorkaround::to_jfieldID(field_holder, entry->field_offset(), is_static);
1200   LastFrameAccessor last_frame(current);
1201   JvmtiExport::post_field_access(current, last_frame.method(), last_frame.bcp(), field_holder, h_obj, fid);
1202 JRT_END
1203 
1204 JRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread* current, oopDesc* obj,
1205                                                             ResolvedFieldEntry *entry, jvalue *value))
1206 

1207   InstanceKlass* ik = entry->field_holder();
1208 
1209   // check the access_flags for the field in the klass
1210   int index = entry->field_index();
1211   // bail out if field modifications are not watched
1212   if (!ik->field_status(index).is_modification_watched()) return;
1213 
1214   char sig_type = '\0';
1215 
1216   switch((TosState)entry->tos_state()) {
1217     case btos: sig_type = JVM_SIGNATURE_BYTE;    break;
1218     case ztos: sig_type = JVM_SIGNATURE_BOOLEAN; break;
1219     case ctos: sig_type = JVM_SIGNATURE_CHAR;    break;
1220     case stos: sig_type = JVM_SIGNATURE_SHORT;   break;
1221     case itos: sig_type = JVM_SIGNATURE_INT;     break;
1222     case ftos: sig_type = JVM_SIGNATURE_FLOAT;   break;
1223     case atos: sig_type = JVM_SIGNATURE_CLASS;   break;
1224     case ltos: sig_type = JVM_SIGNATURE_LONG;    break;
1225     case dtos: sig_type = JVM_SIGNATURE_DOUBLE;  break;
1226     default:  ShouldNotReachHere(); return;
1227   }

1228   bool is_static = (obj == nullptr);

1229 
1230   HandleMark hm(current);
1231   jfieldID fid = jfieldIDWorkaround::to_jfieldID(ik, entry->field_offset(), is_static);
1232   jvalue fvalue;
1233 #ifdef _LP64
1234   fvalue = *value;
1235 #else
1236   // Long/double values are stored unaligned and also noncontiguously with
1237   // tagged stacks.  We can't just do a simple assignment even in the non-
1238   // J/D cases because a C++ compiler is allowed to assume that a jvalue is
1239   // 8-byte aligned, and interpreter stack slots are only 4-byte aligned.
1240   // We assume that the two halves of longs/doubles are stored in interpreter
1241   // stack slots in platform-endian order.
1242   jlong_accessor u;
1243   jint* newval = (jint*)value;
1244   u.words[0] = newval[0];
1245   u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
1246   fvalue.j = u.long_value;
1247 #endif // _LP64
1248 
1249   Handle h_obj;
1250   if (!is_static) {
1251     // non-static field accessors have an object, but we need a handle

   7  * published by the Free Software Foundation.
   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 "classfile/javaClasses.inline.hpp"
  26 #include "classfile/symbolTable.hpp"
  27 #include "classfile/systemDictionary.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/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/method.inline.hpp"
  55 #include "oops/objArrayKlass.hpp"
  56 #include "oops/objArrayOop.inline.hpp"
  57 #include "oops/oop.inline.hpp"
  58 #include "oops/symbol.hpp"
  59 #include "prims/jvmtiExport.hpp"
  60 #include "prims/methodHandles.hpp"
  61 #include "prims/nativeLookup.hpp"
  62 #include "runtime/atomic.hpp"
  63 #include "runtime/continuation.hpp"
  64 #include "runtime/deoptimization.hpp"
  65 #include "runtime/fieldDescriptor.inline.hpp"
  66 #include "runtime/frame.inline.hpp"
  67 #include "runtime/handles.inline.hpp"
  68 #include "runtime/icache.hpp"
  69 #include "runtime/interfaceSupport.inline.hpp"
  70 #include "runtime/java.hpp"
  71 #include "runtime/javaCalls.hpp"
  72 #include "runtime/jfieldIDWorkaround.hpp"
  73 #include "runtime/osThread.hpp"
  74 #include "runtime/sharedRuntime.hpp"
  75 #include "runtime/stackWatermarkSet.hpp"
  76 #include "runtime/stubRoutines.hpp"
  77 #include "runtime/synchronizer.inline.hpp"
  78 #include "runtime/threadCritical.hpp"
  79 #include "utilities/align.hpp"
  80 #include "utilities/checkedCast.hpp"
  81 #include "utilities/copy.hpp"
  82 #include "utilities/events.hpp"
  83 #include "utilities/globalDefinitions.hpp"
  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); }
 101 
 102   // pass method to avoid calling unsafe bcp_to_method (partial fix 4926272)
 103   Bytecodes::Code code() const                   { return Bytecodes::code_at(method(), bcp()); }

 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   oop obj = klass->allocate_instance(CHECK);
 228   current->set_vm_result(obj);
 229 JRT_END
 230 
 231 JRT_ENTRY(void, InterpreterRuntime::uninitialized_static_inline_type_field(JavaThread* current, oopDesc* mirror, ResolvedFieldEntry* entry))
 232   // The interpreter tries to access an inline static field that has not been initialized.
 233   // This situation can happen in different scenarios:
 234   //   1 - if the load or initialization of the field failed during step 8 of
 235   //       the initialization of the holder of the field, in this case the access to the field
 236   //       must fail
 237   //   2 - it can also happen when the initialization of the holder class triggered the initialization of
 238   //       another class which accesses this field in its static initializer, in this case the
 239   //       access must succeed to allow circularity
 240   // The code below tries to load and initialize the field's class again before returning the default value.
 241   // If the field was not initialized because of an error, an exception should be thrown.
 242   // If the class is being initialized, the default value is returned.
 243   assert(entry->is_valid(), "Invalid ResolvedFieldEntry");
 244   instanceHandle mirror_h(THREAD, (instanceOop)mirror);
 245   InstanceKlass* klass = entry->field_holder();
 246   u2 index = entry->field_index();
 247   assert(klass == java_lang_Class::as_Klass(mirror), "Not the field holder klass");
 248   assert(klass->field_is_null_free_inline_type(index), "Sanity check");
 249   if (klass->is_being_initialized() && klass->is_reentrant_initialization(THREAD)) {
 250     int offset = klass->field_offset(index);
 251     Klass* field_k = klass->get_inline_type_field_klass_or_null(index);
 252     if (field_k == nullptr) {
 253       field_k = SystemDictionary::resolve_or_fail(klass->field_signature(index)->fundamental_name(THREAD),
 254           Handle(THREAD, klass->class_loader()),
 255           true, CHECK);
 256       assert(field_k != nullptr, "Should have been loaded or an exception thrown above");
 257       if (!field_k->is_inline_klass()) {
 258         THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(),
 259                   err_msg("class %s expects class %s to be a concrete value class but it is not",
 260                   klass->name()->as_C_string(), field_k->external_name()));
 261       }
 262       InlineLayoutInfo* li = klass->inline_layout_info_adr(index);
 263       li->set_klass(InlineKlass::cast(field_k));
 264       li->set_kind(LayoutKind::REFERENCE);
 265     }
 266     field_k->initialize(CHECK);
 267     oop defaultvalue = InlineKlass::cast(field_k)->default_value();
 268     // It is safe to initialize the static field because 1) the current thread is the initializing thread
 269     // and is the only one that can access it, and 2) the field is actually not initialized (i.e. null)
 270     // otherwise the JVM should not be executing this code.
 271     mirror_h()->obj_field_put(offset, defaultvalue);
 272     current->set_vm_result(defaultvalue);
 273   } else {
 274     assert(klass->is_in_error_state(), "If not initializing, initialization must have failed to get there");
 275     ResourceMark rm(THREAD);
 276     const char* desc = "Could not initialize class ";
 277     const char* className = klass->external_name();
 278     size_t msglen = strlen(desc) + strlen(className) + 1;
 279     char* message = NEW_RESOURCE_ARRAY(char, msglen);
 280     if (nullptr == message) {
 281       // Out of memory: can't create detailed error message
 282       THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), className);
 283     } else {
 284       jio_snprintf(message, msglen, "%s%s", desc, className);
 285       THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), message);
 286     }
 287   }
 288 JRT_END
 289 
 290 JRT_ENTRY(void, InterpreterRuntime::read_flat_field(JavaThread* current, oopDesc* obj, ResolvedFieldEntry* entry))
 291   assert(oopDesc::is_oop(obj), "Sanity check");
 292   Handle obj_h(THREAD, obj);
 293 
 294   InstanceKlass* holder = InstanceKlass::cast(entry->field_holder());
 295   assert(entry->field_holder()->field_is_flat(entry->field_index()), "Sanity check");
 296 
 297   InlineLayoutInfo* layout_info = holder->inline_layout_info_adr(entry->field_index());
 298   InlineKlass* field_vklass = layout_info->klass();
 299 
 300 #ifdef ASSERT
 301   fieldDescriptor fd;
 302   bool found = holder->find_field_from_offset(entry->field_offset(), false, &fd);
 303   assert(found, "Field not found");
 304   assert(fd.is_flat(), "Field must be flat");
 305 #endif // ASSERT
 306 
 307   oop res = field_vklass->read_payload_from_addr(obj_h(), entry->field_offset(), layout_info->kind(), CHECK);
 308   current->set_vm_result(res);
 309 JRT_END
 310 
 311 JRT_ENTRY(void, InterpreterRuntime::read_nullable_flat_field(JavaThread* current, oopDesc* obj, ResolvedFieldEntry* entry))
 312   assert(oopDesc::is_oop(obj), "Sanity check");
 313   assert(entry->has_null_marker(), "Otherwise should not get there");
 314   Handle obj_h(THREAD, obj);
 315 
 316   InstanceKlass* holder = entry->field_holder();
 317   int field_index = entry->field_index();
 318   InlineLayoutInfo* li= holder->inline_layout_info_adr(field_index);
 319 
 320 #ifdef ASSERT
 321   fieldDescriptor fd;
 322   bool found = holder->find_field_from_offset(entry->field_offset(), false, &fd);
 323   assert(found, "Field not found");
 324   assert(fd.is_flat(), "Field must be flat");
 325 #endif // ASSERT
 326 
 327   InlineKlass* field_vklass = InlineKlass::cast(li->klass());
 328   oop res = field_vklass->read_payload_from_addr(obj_h(), entry->field_offset(), li->kind(), CHECK);
 329   current->set_vm_result(res);
 330 
 331 JRT_END
 332 
 333 JRT_ENTRY(void, InterpreterRuntime::write_nullable_flat_field(JavaThread* current, oopDesc* obj, oopDesc* value, ResolvedFieldEntry* entry))
 334   assert(oopDesc::is_oop(obj), "Sanity check");
 335   Handle obj_h(THREAD, obj);
 336   assert(value == nullptr || oopDesc::is_oop(value), "Sanity check");
 337   Handle val_h(THREAD, value);
 338 
 339   InstanceKlass* holder = entry->field_holder();
 340   InlineLayoutInfo* li = holder->inline_layout_info_adr(entry->field_index());
 341   InlineKlass* vk = li->klass();
 342   vk->write_value_to_addr(val_h(), ((char*)(oopDesc*)obj_h()) + entry->field_offset(), li->kind(), true, CHECK);
 343 JRT_END
 344 
 345 JRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* current, BasicType type, jint size))
 346   oop obj = oopFactory::new_typeArray(type, size, CHECK);
 347   current->set_vm_result(obj);
 348 JRT_END
 349 
 350 
 351 JRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* current, ConstantPool* pool, int index, jint size))
 352   Klass*    klass = pool->klass_at(index, CHECK);
 353   arrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
 354   current->set_vm_result(obj);
 355 JRT_END
 356 
 357 JRT_ENTRY(void, InterpreterRuntime::flat_array_load(JavaThread* current, arrayOopDesc* array, int index))
 358   assert(array->is_flatArray(), "Must be");
 359   flatArrayOop farray = (flatArrayOop)array;
 360   oop res = farray->read_value_from_flat_array(index, CHECK);
 361   current->set_vm_result(res);
 362 JRT_END
 363 
 364 JRT_ENTRY(void, InterpreterRuntime::flat_array_store(JavaThread* current, oopDesc* val, arrayOopDesc* array, int index))
 365   assert(array->is_flatArray(), "Must be");
 366   flatArrayOop farray = (flatArrayOop)array;
 367   farray->write_value_to_flat_array(val, index, CHECK);
 368 JRT_END
 369 
 370 JRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* current, jint* first_size_address))
 371   // We may want to pass in more arguments - could make this slightly faster
 372   LastFrameAccessor last_frame(current);
 373   ConstantPool* constants = last_frame.method()->constants();
 374   int i = last_frame.get_index_u2(Bytecodes::_multianewarray);
 375   Klass* klass = constants->klass_at(i, CHECK);
 376   int   nof_dims = last_frame.number_of_dimensions();
 377   assert(klass->is_klass(), "not a class");
 378   assert(nof_dims >= 1, "multianewarray rank must be nonzero");
 379 
 380   // We must create an array of jints to pass to multi_allocate.
 381   ResourceMark rm(current);
 382   const int small_dims = 10;
 383   jint dim_array[small_dims];
 384   jint *dims = &dim_array[0];
 385   if (nof_dims > small_dims) {
 386     dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
 387   }
 388   for (int index = 0; index < nof_dims; index++) {
 389     // offset from first_size_address is addressed as local[index]
 390     int n = Interpreter::local_offset_in_bytes(index)/jintSize;
 391     dims[index] = first_size_address[n];
 392   }
 393   oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
 394   current->set_vm_result(obj);
 395 JRT_END
 396 
 397 
 398 JRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* current, oopDesc* obj))
 399   assert(oopDesc::is_oop(obj), "must be a valid oop");
 400   assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
 401   InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
 402 JRT_END
 403 
 404 JRT_ENTRY(jboolean, InterpreterRuntime::is_substitutable(JavaThread* current, oopDesc* aobj, oopDesc* bobj))
 405   assert(oopDesc::is_oop(aobj) && oopDesc::is_oop(bobj), "must be valid oops");
 406 
 407   Handle ha(THREAD, aobj);
 408   Handle hb(THREAD, bobj);
 409   JavaValue result(T_BOOLEAN);
 410   JavaCallArguments args;
 411   args.push_oop(ha);
 412   args.push_oop(hb);
 413   methodHandle method(current, Universe::is_substitutable_method());
 414   method->method_holder()->initialize(CHECK_false); // Ensure class ValueObjectMethods is initialized
 415   JavaCalls::call(&result, method, &args, THREAD);
 416   if (HAS_PENDING_EXCEPTION) {
 417     // Something really bad happened because isSubstitutable() should not throw exceptions
 418     // If it is an error, just let it propagate
 419     // If it is an exception, wrap it into an InternalError
 420     if (!PENDING_EXCEPTION->is_a(vmClasses::Error_klass())) {
 421       Handle e(THREAD, PENDING_EXCEPTION);
 422       CLEAR_PENDING_EXCEPTION;
 423       THROW_MSG_CAUSE_(vmSymbols::java_lang_InternalError(), "Internal error in substitutability test", e, false);
 424     }
 425   }
 426   return result.get_jboolean();
 427 JRT_END
 428 
 429 // Quicken instance-of and check-cast bytecodes
 430 JRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* current))
 431   // Force resolving; quicken the bytecode
 432   LastFrameAccessor last_frame(current);
 433   int which = last_frame.get_index_u2(Bytecodes::_checkcast);
 434   ConstantPool* cpool = last_frame.method()->constants();
 435   // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
 436   // program we might have seen an unquick'd bytecode in the interpreter but have another
 437   // thread quicken the bytecode before we get here.
 438   // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
 439   Klass* klass = cpool->klass_at(which, CHECK);
 440   current->set_vm_result_2(klass);
 441 JRT_END
 442 
 443 
 444 //------------------------------------------------------------------------------------------------------------------------
 445 // Exceptions
 446 
 447 void InterpreterRuntime::note_trap_inner(JavaThread* current, int reason,

 751 // and therefore we don't have the receiver object at our fingertips. (Though,
 752 // on some platforms the receiver still resides in a register...). Thus,
 753 // we have no choice but print an error message not containing the receiver
 754 // type.
 755 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorWithMethod(JavaThread* current,
 756                                                                         Method* missingMethod))
 757   ResourceMark rm(current);
 758   assert(missingMethod != nullptr, "sanity");
 759   methodHandle m(current, missingMethod);
 760   LinkResolver::throw_abstract_method_error(m, THREAD);
 761 JRT_END
 762 
 763 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorVerbose(JavaThread* current,
 764                                                                      Klass* recvKlass,
 765                                                                      Method* missingMethod))
 766   ResourceMark rm(current);
 767   methodHandle mh = methodHandle(current, missingMethod);
 768   LinkResolver::throw_abstract_method_error(mh, recvKlass, THREAD);
 769 JRT_END
 770 
 771 JRT_ENTRY(void, InterpreterRuntime::throw_InstantiationError(JavaThread* current))
 772   THROW(vmSymbols::java_lang_InstantiationError());
 773 JRT_END
 774 
 775 
 776 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* current))
 777   THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
 778 JRT_END
 779 
 780 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose(JavaThread* current,
 781                                                                               Klass* recvKlass,
 782                                                                               Klass* interfaceKlass))
 783   ResourceMark rm(current);
 784   char buf[1000];
 785   buf[0] = '\0';
 786   jio_snprintf(buf, sizeof(buf),
 787                "Class %s does not implement the requested interface %s",
 788                recvKlass ? recvKlass->external_name() : "nullptr",
 789                interfaceKlass ? interfaceKlass->external_name() : "nullptr");
 790   THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
 791 JRT_END
 792 
 793 JRT_ENTRY(void, InterpreterRuntime::throw_NullPointerException(JavaThread* current))
 794   THROW(vmSymbols::java_lang_NullPointerException());

 839   // initializer method <init>. If resolution were not inhibited, a putfield
 840   // in an initializer method could be resolved in the initializer. Subsequent
 841   // putfield instructions to the same field would then use cached information.
 842   // As a result, those instructions would not pass through the VM. That is,
 843   // checks in resolve_field_access() would not be executed for those instructions
 844   // and the required IllegalAccessError would not be thrown.
 845   //
 846   // Also, we need to delay resolving getstatic and putstatic instructions until the
 847   // class is initialized.  This is required so that access to the static
 848   // field will call the initialization function every time until the class
 849   // is completely initialized ala. in 2.17.5 in JVM Specification.
 850   InstanceKlass* klass = info.field_holder();
 851   bool uninitialized_static = is_static && !klass->is_initialized();
 852   bool has_initialized_final_update = info.field_holder()->major_version() >= 53 &&
 853                                       info.has_initialized_final_update();
 854   assert(!(has_initialized_final_update && !info.access_flags().is_final()), "Fields with initialized final updates must be final");
 855 
 856   Bytecodes::Code get_code = (Bytecodes::Code)0;
 857   Bytecodes::Code put_code = (Bytecodes::Code)0;
 858   if (!uninitialized_static) {
 859     if (is_static) {
 860       get_code = Bytecodes::_getstatic;
 861     } else {
 862       get_code = Bytecodes::_getfield;
 863     }
 864     if ((is_put && !has_initialized_final_update) || !info.access_flags().is_final()) {
 865         put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
 866     }
 867   }
 868 
 869   ResolvedFieldEntry* entry = pool->resolved_field_entry_at(field_index);
 870   entry->set_flags(info.access_flags().is_final(), info.access_flags().is_volatile(),
 871                    info.is_flat(), info.is_null_free_inline_type(),
 872                    info.has_null_marker());
 873 
 874   entry->fill_in(info.field_holder(), info.offset(),
 875                  checked_cast<u2>(info.index()), checked_cast<u1>(state),
 876                  static_cast<u1>(get_code), static_cast<u1>(put_code));
 877 }
 878 
 879 
 880 //------------------------------------------------------------------------------------------------------------------------
 881 // Synchronization
 882 //
 883 // The interpreter's synchronization code is factored out so that it can
 884 // be shared by method invocation and synchronized blocks.
 885 //%note synchronization_3
 886 
 887 //%note monitor_1
 888 JRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* current, BasicObjectLock* elem))
 889 #ifdef ASSERT
 890   current->last_frame().interpreter_frame_verify_monitor(elem);
 891 #endif
 892   Handle h_obj(current, elem->obj());
 893   assert(Universe::heap()->is_in_or_null(h_obj()),

 900 #endif
 901 JRT_END
 902 
 903 JRT_LEAF(void, InterpreterRuntime::monitorexit(BasicObjectLock* elem))
 904   oop obj = elem->obj();
 905   assert(Universe::heap()->is_in(obj), "must be an object");
 906   // The object could become unlocked through a JNI call, which we have no other checks for.
 907   // Give a fatal message if CheckJNICalls. Otherwise we ignore it.
 908   if (obj->is_unlocked()) {
 909     if (CheckJNICalls) {
 910       fatal("Object has been unlocked by JNI");
 911     }
 912     return;
 913   }
 914   ObjectSynchronizer::exit(obj, elem->lock(), JavaThread::current());
 915   // Free entry. If it is not cleared, the exception handling code will try to unlock the monitor
 916   // again at method exit or in the case of an exception.
 917   elem->set_obj(nullptr);
 918 JRT_END
 919 

 920 JRT_ENTRY(void, InterpreterRuntime::throw_illegal_monitor_state_exception(JavaThread* current))
 921   THROW(vmSymbols::java_lang_IllegalMonitorStateException());
 922 JRT_END
 923 

 924 JRT_ENTRY(void, InterpreterRuntime::new_illegal_monitor_state_exception(JavaThread* current))
 925   // Returns an illegal exception to install into the current thread. The
 926   // pending_exception flag is cleared so normal exception handling does not
 927   // trigger. Any current installed exception will be overwritten. This
 928   // method will be called during an exception unwind.
 929 
 930   assert(!HAS_PENDING_EXCEPTION, "no pending exception");
 931   Handle exception(current, current->vm_result());
 932   assert(exception() != nullptr, "vm result should be set");
 933   current->set_vm_result(nullptr); // clear vm result before continuing (may cause memory leaks and assert failures)
 934   exception = get_preinitialized_exception(vmClasses::IllegalMonitorStateException_klass(), CATCH);
 935   current->set_vm_result(exception());
 936 JRT_END
 937 
 938 JRT_ENTRY(void, InterpreterRuntime::throw_identity_exception(JavaThread* current, oopDesc* obj))
 939   Klass* klass = cast_to_oop(obj)->klass();
 940   ResourceMark rm(THREAD);
 941   const char* desc = "Cannot synchronize on an instance of value class ";
 942   const char* className = klass->external_name();
 943   size_t msglen = strlen(desc) + strlen(className) + 1;
 944   char* message = NEW_RESOURCE_ARRAY(char, msglen);
 945   if (nullptr == message) {
 946     // Out of memory: can't create detailed error message
 947     THROW_MSG(vmSymbols::java_lang_IdentityException(), className);
 948   } else {
 949     jio_snprintf(message, msglen, "%s%s", desc, className);
 950     THROW_MSG(vmSymbols::java_lang_IdentityException(), message);
 951   }
 952 JRT_END
 953 
 954 //------------------------------------------------------------------------------------------------------------------------
 955 // Invokes
 956 
 957 JRT_ENTRY(Bytecodes::Code, InterpreterRuntime::get_original_bytecode_at(JavaThread* current, Method* method, address bcp))
 958   return method->orig_bytecode_at(method->bci_from(bcp));
 959 JRT_END
 960 
 961 JRT_ENTRY(void, InterpreterRuntime::set_original_bytecode_at(JavaThread* current, Method* method, address bcp, Bytecodes::Code new_code))
 962   method->set_orig_bytecode_at(method->bci_from(bcp), new_code);
 963 JRT_END
 964 
 965 JRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* current, Method* method, address bcp))
 966   JvmtiExport::post_raw_breakpoint(current, method, bcp);
 967 JRT_END
 968 
 969 void InterpreterRuntime::resolve_invoke(JavaThread* current, Bytecodes::Code bytecode) {
 970   LastFrameAccessor last_frame(current);
 971   // extract receiver from the outgoing argument list if necessary
 972   Handle receiver(current, nullptr);

1342     LastFrameAccessor last_frame(current);
1343     JvmtiExport::at_single_stepping_point(current, last_frame.method(), last_frame.bcp());
1344   }
1345 JRT_END
1346 
1347 JRT_LEAF(void, InterpreterRuntime::at_unwind(JavaThread* current))
1348   assert(current == JavaThread::current(), "pre-condition");
1349   // This function is called by the interpreter when the return poll found a reason
1350   // to call the VM. The reason could be that we are returning into a not yet safe
1351   // to access frame. We handle that below.
1352   // Note that this path does not check for single stepping, because we do not want
1353   // to single step when unwinding frames for an exception being thrown. Instead,
1354   // such single stepping code will use the safepoint table, which will use the
1355   // InterpreterRuntime::at_safepoint callback.
1356   StackWatermarkSet::before_unwind(current);
1357 JRT_END
1358 
1359 JRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread* current, oopDesc* obj,
1360                                                       ResolvedFieldEntry *entry))
1361 
1362   assert(entry->is_valid(), "Invalid ResolvedFieldEntry");
1363   // check the access_flags for the field in the klass
1364 
1365   InstanceKlass* ik = entry->field_holder();
1366   int index = entry->field_index();
1367   if (!ik->field_status(index).is_access_watched()) return;
1368 
1369   bool is_static = (obj == nullptr);
1370   bool is_flat = entry->is_flat();
1371   HandleMark hm(current);
1372 
1373   Handle h_obj;
1374   if (!is_static) {
1375     // non-static field accessors have an object, but we need a handle
1376     h_obj = Handle(current, obj);
1377   }
1378   InstanceKlass* field_holder = entry->field_holder(); // HERE
1379   jfieldID fid = jfieldIDWorkaround::to_jfieldID(field_holder, entry->field_offset(), is_static, is_flat);
1380   LastFrameAccessor last_frame(current);
1381   JvmtiExport::post_field_access(current, last_frame.method(), last_frame.bcp(), field_holder, h_obj, fid);
1382 JRT_END
1383 
1384 JRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread* current, oopDesc* obj,
1385                                                             ResolvedFieldEntry *entry, jvalue *value))
1386 
1387   assert(entry->is_valid(), "Invalid ResolvedFieldEntry");
1388   InstanceKlass* ik = entry->field_holder();
1389 
1390   // check the access_flags for the field in the klass
1391   int index = entry->field_index();
1392   // bail out if field modifications are not watched
1393   if (!ik->field_status(index).is_modification_watched()) return;
1394 
1395   char sig_type = '\0';
1396 
1397   switch((TosState)entry->tos_state()) {
1398     case btos: sig_type = JVM_SIGNATURE_BYTE;    break;
1399     case ztos: sig_type = JVM_SIGNATURE_BOOLEAN; break;
1400     case ctos: sig_type = JVM_SIGNATURE_CHAR;    break;
1401     case stos: sig_type = JVM_SIGNATURE_SHORT;   break;
1402     case itos: sig_type = JVM_SIGNATURE_INT;     break;
1403     case ftos: sig_type = JVM_SIGNATURE_FLOAT;   break;
1404     case atos: sig_type = JVM_SIGNATURE_CLASS;   break;
1405     case ltos: sig_type = JVM_SIGNATURE_LONG;    break;
1406     case dtos: sig_type = JVM_SIGNATURE_DOUBLE;  break;
1407     default:  ShouldNotReachHere(); return;
1408   }
1409 
1410   bool is_static = (obj == nullptr);
1411   bool is_flat = entry->is_flat();
1412 
1413   HandleMark hm(current);
1414   jfieldID fid = jfieldIDWorkaround::to_jfieldID(ik, entry->field_offset(), is_static, is_flat);
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 >