< prev index next >

src/hotspot/share/interpreter/interpreterRuntime.cpp

Print this page

   1 /*
   2  * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   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 "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.inline.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); }

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


















































































































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












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
























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

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




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

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




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



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

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















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

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

1171   // check the access_flags for the field in the klass
1172 
1173   InstanceKlass* ik = entry->field_holder();
1174   int index = entry->field_index();
1175   if (!ik->field_status(index).is_access_watched()) return;
1176 
1177   bool is_static = (obj == nullptr);

1178   HandleMark hm(current);
1179 
1180   Handle h_obj;
1181   if (!is_static) {
1182     // non-static field accessors have an object, but we need a handle
1183     h_obj = Handle(current, obj);
1184   }
1185   InstanceKlass* field_holder = entry->field_holder(); // HERE
1186   jfieldID fid = jfieldIDWorkaround::to_jfieldID(field_holder, entry->field_offset(), is_static);
1187   LastFrameAccessor last_frame(current);
1188   JvmtiExport::post_field_access(current, last_frame.method(), last_frame.bcp(), field_holder, h_obj, fid);
1189 JRT_END
1190 
1191 JRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread* current, oopDesc* obj,
1192                                                             ResolvedFieldEntry *entry, jvalue *value))
1193 

1194   InstanceKlass* ik = entry->field_holder();
1195 
1196   // check the access_flags for the field in the klass
1197   int index = entry->field_index();
1198   // bail out if field modifications are not watched
1199   if (!ik->field_status(index).is_modification_watched()) return;
1200 
1201   char sig_type = '\0';
1202 
1203   switch((TosState)entry->tos_state()) {
1204     case btos: sig_type = JVM_SIGNATURE_BYTE;    break;
1205     case ztos: sig_type = JVM_SIGNATURE_BOOLEAN; break;
1206     case ctos: sig_type = JVM_SIGNATURE_CHAR;    break;
1207     case stos: sig_type = JVM_SIGNATURE_SHORT;   break;
1208     case itos: sig_type = JVM_SIGNATURE_INT;     break;
1209     case ftos: sig_type = JVM_SIGNATURE_FLOAT;   break;
1210     case atos: sig_type = JVM_SIGNATURE_CLASS;   break;
1211     case ltos: sig_type = JVM_SIGNATURE_LONG;    break;
1212     case dtos: sig_type = JVM_SIGNATURE_DOUBLE;  break;
1213     default:  ShouldNotReachHere(); return;
1214   }

1215   bool is_static = (obj == nullptr);

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

   1 /*
   2  * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   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 "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.inline.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); }

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

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

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

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

 925 JRT_ENTRY(void, InterpreterRuntime::throw_illegal_monitor_state_exception(JavaThread* current))
 926   THROW(vmSymbols::java_lang_IllegalMonitorStateException());
 927 JRT_END
 928 

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

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