< 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/oopMapCache.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/method.inline.hpp"
  51 #include "oops/methodData.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/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.hpp"
  74 #include "utilities/align.hpp"
  75 #include "utilities/checkedCast.hpp"
  76 #include "utilities/copy.hpp"
  77 #include "utilities/events.hpp"
  78 #include "utilities/exceptions.hpp"

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

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






















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












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
















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

 588 // and therefore we don't have the receiver object at our fingertips. (Though,
 589 // on some platforms the receiver still resides in a register...). Thus,
 590 // we have no choice but print an error message not containing the receiver
 591 // type.
 592 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorWithMethod(JavaThread* current,
 593                                                                         Method* missingMethod))
 594   ResourceMark rm(current);
 595   assert(missingMethod != nullptr, "sanity");
 596   methodHandle m(current, missingMethod);
 597   LinkResolver::throw_abstract_method_error(m, THREAD);
 598 JRT_END
 599 
 600 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorVerbose(JavaThread* current,
 601                                                                      Klass* recvKlass,
 602                                                                      Method* missingMethod))
 603   ResourceMark rm(current);
 604   methodHandle mh = methodHandle(current, missingMethod);
 605   LinkResolver::throw_abstract_method_error(mh, recvKlass, THREAD);
 606 JRT_END
 607 
 608 
 609 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* current))
 610   THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
 611 JRT_END
 612 
 613 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose(JavaThread* current,
 614                                                                               Klass* recvKlass,
 615                                                                               Klass* interfaceKlass))
 616   ResourceMark rm(current);
 617   char buf[1000];
 618   buf[0] = '\0';
 619   jio_snprintf(buf, sizeof(buf),
 620                "Class %s does not implement the requested interface %s",
 621                recvKlass ? recvKlass->external_name() : "nullptr",
 622                interfaceKlass ? interfaceKlass->external_name() : "nullptr");
 623   THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
 624 JRT_END
 625 
 626 JRT_ENTRY(void, InterpreterRuntime::throw_NullPointerException(JavaThread* current))
 627   THROW(vmSymbols::java_lang_NullPointerException());
 628 JRT_END

 667 
 668   // Resolution of put instructions to final instance fields with invalid updates (i.e.,
 669   // to final instance fields with updates originating from a method different than <init>)
 670   // is inhibited. A putfield instruction targeting an instance final field must throw
 671   // an IllegalAccessError if the instruction is not in an instance
 672   // initializer method <init>. If resolution were not inhibited, a putfield
 673   // in an initializer method could be resolved in the initializer. Subsequent
 674   // putfield instructions to the same field would then use cached information.
 675   // As a result, those instructions would not pass through the VM. That is,
 676   // checks in resolve_field_access() would not be executed for those instructions
 677   // and the required IllegalAccessError would not be thrown.
 678   //
 679   // Also, we need to delay resolving getstatic and putstatic instructions until the
 680   // class is initialized.  This is required so that access to the static
 681   // field will call the initialization function every time until the class
 682   // is completely initialized ala. in 2.17.5 in JVM Specification.
 683   InstanceKlass* klass = info.field_holder();
 684   bool uninitialized_static = is_static && !klass->is_initialized();
 685   bool has_initialized_final_update = info.field_holder()->major_version() >= 53 &&
 686                                       info.has_initialized_final_update();

 687   assert(!(has_initialized_final_update && !info.access_flags().is_final()), "Fields with initialized final updates must be final");
 688 
 689   Bytecodes::Code get_code = (Bytecodes::Code)0;
 690   Bytecodes::Code put_code = (Bytecodes::Code)0;
 691   if (!uninitialized_static || VM_Version::supports_fast_class_init_checks()) {













 692     get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield);
 693     if ((is_put && !has_initialized_final_update) || !info.access_flags().is_final()) {
 694       put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
 695     }
 696   }
 697 
 698   ResolvedFieldEntry* entry = pool->resolved_field_entry_at(field_index);
 699   entry->fill_in(info, checked_cast<u1>(state),
 700                  static_cast<u1>(get_code), static_cast<u1>(put_code));
 701 }
 702 
 703 
 704 //------------------------------------------------------------------------------------------------------------------------
 705 // Synchronization
 706 //
 707 // The interpreter's synchronization code is factored out so that it can
 708 // be shared by method invocation and synchronized blocks.
 709 //%note synchronization_3
 710 
 711 //%note monitor_1

 742 JRT_END
 743 
 744 JRT_ENTRY(void, InterpreterRuntime::throw_illegal_monitor_state_exception(JavaThread* current))
 745   THROW(vmSymbols::java_lang_IllegalMonitorStateException());
 746 JRT_END
 747 
 748 JRT_ENTRY(void, InterpreterRuntime::new_illegal_monitor_state_exception(JavaThread* current))
 749   // Returns an illegal exception to install into the current thread. The
 750   // pending_exception flag is cleared so normal exception handling does not
 751   // trigger. Any current installed exception will be overwritten. This
 752   // method will be called during an exception unwind.
 753 
 754   assert(!HAS_PENDING_EXCEPTION, "no pending exception");
 755   Handle exception(current, current->vm_result_oop());
 756   assert(exception() != nullptr, "vm result should be set");
 757   current->set_vm_result_oop(nullptr); // clear vm result before continuing (may cause memory leaks and assert failures)
 758   exception = get_preinitialized_exception(vmClasses::IllegalMonitorStateException_klass(), CATCH);
 759   current->set_vm_result_oop(exception());
 760 JRT_END
 761 















 762 
 763 //------------------------------------------------------------------------------------------------------------------------
 764 // Invokes
 765 
 766 JRT_ENTRY(Bytecodes::Code, InterpreterRuntime::get_original_bytecode_at(JavaThread* current, Method* method, address bcp))
 767   return method->orig_bytecode_at(method->bci_from(bcp));
 768 JRT_END
 769 
 770 JRT_ENTRY(void, InterpreterRuntime::set_original_bytecode_at(JavaThread* current, Method* method, address bcp, Bytecodes::Code new_code))
 771   method->set_orig_bytecode_at(method->bci_from(bcp), new_code);
 772 JRT_END
 773 
 774 JRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* current, Method* method, address bcp))
 775   JvmtiExport::post_raw_breakpoint(current, method, bcp);
 776 JRT_END
 777 
 778 void InterpreterRuntime::resolve_invoke(Bytecodes::Code bytecode, TRAPS) {
 779   JavaThread* current = THREAD;
 780   LastFrameAccessor last_frame(current);
 781   // extract receiver from the outgoing argument list if necessary

1165   JFR_ONLY(Jfr::check_and_process_sample_request(current);)
1166   // This function is called by the interpreter when the return poll found a reason
1167   // to call the VM. The reason could be that we are returning into a not yet safe
1168   // to access frame. We handle that below.
1169   // Note that this path does not check for single stepping, because we do not want
1170   // to single step when unwinding frames for an exception being thrown. Instead,
1171   // such single stepping code will use the safepoint table, which will use the
1172   // InterpreterRuntime::at_safepoint callback.
1173   StackWatermarkSet::before_unwind(current);
1174 JRT_END
1175 
1176 JRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread* current, oopDesc* obj,
1177                                                       ResolvedFieldEntry* entry))
1178 
1179   // check the access_flags for the field in the klass
1180   InstanceKlass* ik = entry->field_holder();
1181   int index = entry->field_index();
1182   if (!ik->field_status(index).is_access_watched()) return;
1183 
1184   bool is_static = (obj == nullptr);

1185   HandleMark hm(current);
1186 
1187   Handle h_obj;
1188   if (!is_static) {
1189     // non-static field accessors have an object, but we need a handle
1190     h_obj = Handle(current, obj);
1191   }
1192   InstanceKlass* field_holder = entry->field_holder(); // HERE
1193   jfieldID fid = jfieldIDWorkaround::to_jfieldID(field_holder, entry->field_offset(), is_static);
1194   LastFrameAccessor last_frame(current);
1195   JvmtiExport::post_field_access(current, last_frame.method(), last_frame.bcp(), field_holder, h_obj, fid);
1196 JRT_END
1197 
1198 JRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread* current, oopDesc* obj,
1199                                                             ResolvedFieldEntry* entry, jvalue* value))
1200 
1201   // check the access_flags for the field in the klass
1202   InstanceKlass* ik = entry->field_holder();
1203   int index = entry->field_index();
1204   // bail out if field modifications are not watched
1205   if (!ik->field_status(index).is_modification_watched()) return;
1206 
1207   char sig_type = '\0';
1208 
1209   switch((TosState)entry->tos_state()) {
1210     case btos: sig_type = JVM_SIGNATURE_BYTE;    break;
1211     case ztos: sig_type = JVM_SIGNATURE_BOOLEAN; break;
1212     case ctos: sig_type = JVM_SIGNATURE_CHAR;    break;
1213     case stos: sig_type = JVM_SIGNATURE_SHORT;   break;
1214     case itos: sig_type = JVM_SIGNATURE_INT;     break;
1215     case ftos: sig_type = JVM_SIGNATURE_FLOAT;   break;
1216     case atos: sig_type = JVM_SIGNATURE_CLASS;   break;
1217     case ltos: sig_type = JVM_SIGNATURE_LONG;    break;
1218     case dtos: sig_type = JVM_SIGNATURE_DOUBLE;  break;
1219     default:  ShouldNotReachHere(); return;
1220   }

1221   bool is_static = (obj == nullptr);

1222 
1223   HandleMark hm(current);
1224   jfieldID fid = jfieldIDWorkaround::to_jfieldID(ik, entry->field_offset(), is_static);
1225   jvalue fvalue;
1226 #ifdef _LP64
1227   fvalue = *value;
1228 #else
1229   // Long/double values are stored unaligned and also noncontiguously with
1230   // tagged stacks.  We can't just do a simple assignment even in the non-
1231   // J/D cases because a C++ compiler is allowed to assume that a jvalue is
1232   // 8-byte aligned, and interpreter stack slots are only 4-byte aligned.
1233   // We assume that the two halves of longs/doubles are stored in interpreter
1234   // stack slots in platform-endian order.
1235   jlong_accessor u;
1236   jint* newval = (jint*)value;
1237   u.words[0] = newval[0];
1238   u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
1239   fvalue.j = u.long_value;
1240 #endif // _LP64
1241 
1242   Handle h_obj;
1243   if (!is_static) {
1244     // 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/oopMapCache.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/method.inline.hpp"
  55 #include "oops/methodData.hpp"
  56 #include "oops/objArrayKlass.hpp"
  57 #include "oops/objArrayOop.inline.hpp"
  58 #include "oops/oop.inline.hpp"
  59 #include "oops/oopsHierarchy.hpp"
  60 #include "oops/symbol.hpp"
  61 #include "oops/valuePayload.inline.hpp"
  62 #include "prims/jvmtiExport.hpp"
  63 #include "prims/methodHandles.hpp"
  64 #include "prims/nativeLookup.hpp"
  65 #include "runtime/continuation.hpp"
  66 #include "runtime/deoptimization.hpp"
  67 #include "runtime/fieldDescriptor.inline.hpp"
  68 #include "runtime/frame.inline.hpp"
  69 #include "runtime/handles.inline.hpp"
  70 #include "runtime/icache.hpp"
  71 #include "runtime/interfaceSupport.inline.hpp"
  72 #include "runtime/java.hpp"
  73 #include "runtime/javaCalls.hpp"
  74 #include "runtime/jfieldIDWorkaround.hpp"
  75 #include "runtime/osThread.hpp"
  76 #include "runtime/sharedRuntime.hpp"
  77 #include "runtime/stackWatermarkSet.hpp"
  78 #include "runtime/stubRoutines.hpp"
  79 #include "runtime/synchronizer.hpp"
  80 #include "utilities/align.hpp"
  81 #include "utilities/checkedCast.hpp"
  82 #include "utilities/copy.hpp"
  83 #include "utilities/events.hpp"
  84 #include "utilities/exceptions.hpp"
  85 #include "utilities/globalDefinitions.hpp"
  86 #if INCLUDE_JFR
  87 #include "jfr/jfr.inline.hpp"
  88 #endif
  89 
  90 // Helper class to access current interpreter state
  91 class LastFrameAccessor : public StackObj {
  92   frame _last_frame;
  93 public:
  94   LastFrameAccessor(JavaThread* current) {
  95     assert(current == Thread::current(), "sanity");
  96     _last_frame = current->last_frame();
  97   }
  98   bool is_interpreted_frame() const              { return _last_frame.is_interpreted_frame(); }
  99   Method*   method() const                       { return _last_frame.interpreter_frame_method(); }
 100   address   bcp() const                          { return _last_frame.interpreter_frame_bcp(); }
 101   int       bci() const                          { return _last_frame.interpreter_frame_bci(); }
 102   address   mdp() const                          { return _last_frame.interpreter_frame_mdp(); }
 103 
 104   void      set_bcp(address bcp)                 { _last_frame.interpreter_frame_set_bcp(bcp); }
 105   void      set_mdp(address dp)                  { _last_frame.interpreter_frame_set_mdp(dp); }

 216 JRT_END
 217 
 218 
 219 //------------------------------------------------------------------------------------------------------------------------
 220 // Allocation
 221 
 222 JRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* current, ConstantPool* pool, int index))
 223   Klass* k = pool->klass_at(index, CHECK);
 224   InstanceKlass* klass = InstanceKlass::cast(k);
 225 
 226   // Make sure we are not instantiating an abstract klass
 227   klass->check_valid_for_instantiation(true, CHECK);
 228 
 229   // Make sure klass is initialized
 230   klass->initialize_preemptable(CHECK_AND_CLEAR_PREEMPTED);
 231 
 232   oop obj = klass->allocate_instance(CHECK);
 233   current->set_vm_result_oop(obj);
 234 JRT_END
 235 
 236 JRT_BLOCK_ENTRY(void, InterpreterRuntime::read_flat_field(JavaThread* current, oopDesc* obj, ResolvedFieldEntry* entry))
 237   assert(oopDesc::is_oop(obj), "Sanity check");
 238 
 239   FlatFieldPayload payload(instanceOop(obj), entry);
 240   if (payload.is_payload_null()) {
 241     // If the payload is null return before entering the JRT_BLOCK.
 242     current->set_vm_result_oop(nullptr);
 243     return;
 244   }
 245   JRT_BLOCK
 246     oop res = payload.read(CHECK);
 247     current->set_vm_result_oop(res);
 248   JRT_BLOCK_END
 249 JRT_END
 250 
 251 JRT_ENTRY(void, InterpreterRuntime::write_flat_field(JavaThread* current, oopDesc* obj, oopDesc* value, ResolvedFieldEntry* entry))
 252   assert(oopDesc::is_oop(obj), "Sanity check");
 253   assert(oopDesc::is_oop_or_null(value), "Sanity check");
 254 
 255   FlatFieldPayload payload(instanceOop(obj), entry);
 256   payload.write(inlineOop(value), CHECK);
 257 JRT_END
 258 
 259 JRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* current, BasicType type, jint size))
 260   oop obj = oopFactory::new_typeArray(type, size, CHECK);
 261   current->set_vm_result_oop(obj);
 262 JRT_END
 263 
 264 
 265 JRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* current, ConstantPool* pool, int index, jint size))
 266   Klass*    klass = pool->klass_at(index, CHECK);
 267   objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
 268   current->set_vm_result_oop(obj);
 269 JRT_END
 270 
 271 JRT_ENTRY(void, InterpreterRuntime::flat_array_load(JavaThread* current, arrayOopDesc* array, int index))
 272   assert(array->is_flatArray(), "Must be");
 273   flatArrayOop farray = (flatArrayOop)array;
 274   oop res = farray->obj_at(index, CHECK);
 275   current->set_vm_result_oop(res);
 276 JRT_END
 277 
 278 JRT_ENTRY(void, InterpreterRuntime::flat_array_store(JavaThread* current, oopDesc* val, arrayOopDesc* array, int index))
 279   assert(array->is_flatArray(), "Must be");
 280   flatArrayOop farray = (flatArrayOop)array;
 281   farray->obj_at_put(index, val, CHECK);
 282 JRT_END
 283 
 284 JRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* current, jint* first_size_address))
 285   // We may want to pass in more arguments - could make this slightly faster
 286   LastFrameAccessor last_frame(current);
 287   ConstantPool* constants = last_frame.method()->constants();
 288   int i = last_frame.get_index_u2(Bytecodes::_multianewarray);
 289   Klass* klass = constants->klass_at(i, CHECK);
 290   int nof_dims = last_frame.number_of_dimensions();
 291   assert(klass->is_klass(), "not a class");
 292   assert(nof_dims >= 1, "multianewarray rank must be nonzero");
 293 
 294   // We must create an array of jints to pass to multi_allocate.
 295   ResourceMark rm(current);
 296   const int small_dims = 10;
 297   jint dim_array[small_dims];
 298   jint *dims = &dim_array[0];
 299   if (nof_dims > small_dims) {
 300     dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
 301   }
 302   for (int index = 0; index < nof_dims; index++) {
 303     // offset from first_size_address is addressed as local[index]
 304     int n = Interpreter::local_offset_in_bytes(index)/jintSize;
 305     dims[index] = first_size_address[n];
 306   }
 307   oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
 308   current->set_vm_result_oop(obj);
 309 JRT_END
 310 
 311 
 312 JRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* current, oopDesc* obj))
 313   assert(oopDesc::is_oop(obj), "must be a valid oop");
 314   assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
 315   InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
 316 JRT_END
 317 
 318 JRT_ENTRY(jboolean, InterpreterRuntime::is_substitutable(JavaThread* current, oopDesc* aobj, oopDesc* bobj))
 319   assert(oopDesc::is_oop(aobj) && oopDesc::is_oop(bobj), "must be valid oops");
 320 
 321   Handle ha(THREAD, aobj);
 322   Handle hb(THREAD, bobj);
 323   JavaValue result(T_BOOLEAN);
 324   JavaCallArguments args;
 325   args.push_oop(ha);
 326   args.push_oop(hb);
 327   methodHandle method(current, Universe::is_substitutable_method());
 328   method->method_holder()->initialize(CHECK_false); // Ensure class ValueObjectMethods is initialized
 329   JavaCalls::call(&result, method, &args, THREAD);
 330   Exceptions::wrap_exception_in_internal_error("Internal error in substitutability test", CHECK_false);
 331 
 332   return result.get_jboolean();
 333 JRT_END
 334 
 335 // Quicken instance-of and check-cast bytecodes
 336 JRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* current))
 337   // Force resolving; quicken the bytecode
 338   LastFrameAccessor last_frame(current);
 339   int which = last_frame.get_index_u2(Bytecodes::_checkcast);
 340   ConstantPool* cpool = last_frame.method()->constants();
 341   // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
 342   // program we might have seen an unquick'd bytecode in the interpreter but have another
 343   // thread quicken the bytecode before we get here.
 344   // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
 345   Klass* klass = cpool->klass_at(which, CHECK);
 346   current->set_vm_result_metadata(klass);
 347 JRT_END
 348 
 349 
 350 //------------------------------------------------------------------------------------------------------------------------
 351 // Exceptions
 352 
 353 void InterpreterRuntime::note_trap_inner(JavaThread* current, int reason,

 645 // and therefore we don't have the receiver object at our fingertips. (Though,
 646 // on some platforms the receiver still resides in a register...). Thus,
 647 // we have no choice but print an error message not containing the receiver
 648 // type.
 649 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorWithMethod(JavaThread* current,
 650                                                                         Method* missingMethod))
 651   ResourceMark rm(current);
 652   assert(missingMethod != nullptr, "sanity");
 653   methodHandle m(current, missingMethod);
 654   LinkResolver::throw_abstract_method_error(m, THREAD);
 655 JRT_END
 656 
 657 JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorVerbose(JavaThread* current,
 658                                                                      Klass* recvKlass,
 659                                                                      Method* missingMethod))
 660   ResourceMark rm(current);
 661   methodHandle mh = methodHandle(current, missingMethod);
 662   LinkResolver::throw_abstract_method_error(mh, recvKlass, THREAD);
 663 JRT_END
 664 

 665 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* current))
 666   THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
 667 JRT_END
 668 
 669 JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose(JavaThread* current,
 670                                                                               Klass* recvKlass,
 671                                                                               Klass* interfaceKlass))
 672   ResourceMark rm(current);
 673   char buf[1000];
 674   buf[0] = '\0';
 675   jio_snprintf(buf, sizeof(buf),
 676                "Class %s does not implement the requested interface %s",
 677                recvKlass ? recvKlass->external_name() : "nullptr",
 678                interfaceKlass ? interfaceKlass->external_name() : "nullptr");
 679   THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
 680 JRT_END
 681 
 682 JRT_ENTRY(void, InterpreterRuntime::throw_NullPointerException(JavaThread* current))
 683   THROW(vmSymbols::java_lang_NullPointerException());
 684 JRT_END

 723 
 724   // Resolution of put instructions to final instance fields with invalid updates (i.e.,
 725   // to final instance fields with updates originating from a method different than <init>)
 726   // is inhibited. A putfield instruction targeting an instance final field must throw
 727   // an IllegalAccessError if the instruction is not in an instance
 728   // initializer method <init>. If resolution were not inhibited, a putfield
 729   // in an initializer method could be resolved in the initializer. Subsequent
 730   // putfield instructions to the same field would then use cached information.
 731   // As a result, those instructions would not pass through the VM. That is,
 732   // checks in resolve_field_access() would not be executed for those instructions
 733   // and the required IllegalAccessError would not be thrown.
 734   //
 735   // Also, we need to delay resolving getstatic and putstatic instructions until the
 736   // class is initialized.  This is required so that access to the static
 737   // field will call the initialization function every time until the class
 738   // is completely initialized ala. in 2.17.5 in JVM Specification.
 739   InstanceKlass* klass = info.field_holder();
 740   bool uninitialized_static = is_static && !klass->is_initialized();
 741   bool has_initialized_final_update = info.field_holder()->major_version() >= 53 &&
 742                                       info.has_initialized_final_update();
 743   bool strict_static_final = info.is_strict() && info.is_static() && info.is_final();
 744   assert(!(has_initialized_final_update && !info.access_flags().is_final()), "Fields with initialized final updates must be final");
 745 
 746   Bytecodes::Code get_code = (Bytecodes::Code)0;
 747   Bytecodes::Code put_code = (Bytecodes::Code)0;
 748   if (uninitialized_static && (info.is_strict_static_unset() || strict_static_final)) {
 749     // During <clinit>, closely track the state of strict statics.
 750     // 1. if we are reading an uninitialized strict static, throw
 751     // 2. if we are writing one, clear the "unset" flag
 752     //
 753     // Note: If we were handling an attempted write of a null to a
 754     // null-restricted strict static, we would NOT clear the "unset"
 755     // flag.
 756     assert(klass->is_being_initialized(), "else should have thrown");
 757     assert(klass->is_reentrant_initialization(THREAD),
 758       "<clinit> must be running in current thread");
 759     klass->notify_strict_static_access(info.index(), is_put, CHECK);
 760     assert(!info.is_strict_static_unset(), "after initialization, no unset flags");
 761   } else if (!uninitialized_static || VM_Version::supports_fast_class_init_checks()) {
 762     get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield);
 763     if ((is_put && !has_initialized_final_update) || !info.access_flags().is_final()) {
 764       put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
 765     }
 766   }
 767 
 768   ResolvedFieldEntry* entry = pool->resolved_field_entry_at(field_index);
 769   entry->fill_in(info, checked_cast<u1>(state),
 770                  static_cast<u1>(get_code), static_cast<u1>(put_code));
 771 }
 772 
 773 
 774 //------------------------------------------------------------------------------------------------------------------------
 775 // Synchronization
 776 //
 777 // The interpreter's synchronization code is factored out so that it can
 778 // be shared by method invocation and synchronized blocks.
 779 //%note synchronization_3
 780 
 781 //%note monitor_1

 812 JRT_END
 813 
 814 JRT_ENTRY(void, InterpreterRuntime::throw_illegal_monitor_state_exception(JavaThread* current))
 815   THROW(vmSymbols::java_lang_IllegalMonitorStateException());
 816 JRT_END
 817 
 818 JRT_ENTRY(void, InterpreterRuntime::new_illegal_monitor_state_exception(JavaThread* current))
 819   // Returns an illegal exception to install into the current thread. The
 820   // pending_exception flag is cleared so normal exception handling does not
 821   // trigger. Any current installed exception will be overwritten. This
 822   // method will be called during an exception unwind.
 823 
 824   assert(!HAS_PENDING_EXCEPTION, "no pending exception");
 825   Handle exception(current, current->vm_result_oop());
 826   assert(exception() != nullptr, "vm result should be set");
 827   current->set_vm_result_oop(nullptr); // clear vm result before continuing (may cause memory leaks and assert failures)
 828   exception = get_preinitialized_exception(vmClasses::IllegalMonitorStateException_klass(), CATCH);
 829   current->set_vm_result_oop(exception());
 830 JRT_END
 831 
 832 JRT_ENTRY(void, InterpreterRuntime::throw_identity_exception(JavaThread* current, oopDesc* obj))
 833   Klass* klass = cast_to_oop(obj)->klass();
 834   ResourceMark rm(THREAD);
 835   const char* desc = "Cannot synchronize on an instance of value class ";
 836   const char* className = klass->external_name();
 837   size_t msglen = strlen(desc) + strlen(className) + 1;
 838   char* message = NEW_RESOURCE_ARRAY(char, msglen);
 839   if (nullptr == message) {
 840     // Out of memory: can't create detailed error message
 841     THROW_MSG(vmSymbols::java_lang_IdentityException(), className);
 842   } else {
 843     jio_snprintf(message, msglen, "%s%s", desc, className);
 844     THROW_MSG(vmSymbols::java_lang_IdentityException(), message);
 845   }
 846 JRT_END
 847 
 848 //------------------------------------------------------------------------------------------------------------------------
 849 // Invokes
 850 
 851 JRT_ENTRY(Bytecodes::Code, InterpreterRuntime::get_original_bytecode_at(JavaThread* current, Method* method, address bcp))
 852   return method->orig_bytecode_at(method->bci_from(bcp));
 853 JRT_END
 854 
 855 JRT_ENTRY(void, InterpreterRuntime::set_original_bytecode_at(JavaThread* current, Method* method, address bcp, Bytecodes::Code new_code))
 856   method->set_orig_bytecode_at(method->bci_from(bcp), new_code);
 857 JRT_END
 858 
 859 JRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* current, Method* method, address bcp))
 860   JvmtiExport::post_raw_breakpoint(current, method, bcp);
 861 JRT_END
 862 
 863 void InterpreterRuntime::resolve_invoke(Bytecodes::Code bytecode, TRAPS) {
 864   JavaThread* current = THREAD;
 865   LastFrameAccessor last_frame(current);
 866   // extract receiver from the outgoing argument list if necessary

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