< prev index next >

src/hotspot/share/interpreter/interpreterRuntime.cpp

Print this page




  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/interpreter.hpp"
  36 #include "interpreter/interpreterRuntime.hpp"
  37 #include "interpreter/linkResolver.hpp"
  38 #include "interpreter/templateTable.hpp"
  39 #include "logging/log.hpp"
  40 #include "memory/oopFactory.hpp"
  41 #include "memory/resourceArea.hpp"
  42 #include "memory/universe.hpp"
  43 #include "oops/constantPool.hpp"
  44 #include "oops/cpCache.inline.hpp"
  45 #include "oops/instanceKlass.hpp"
  46 #include "oops/methodData.hpp"
  47 #include "oops/objArrayKlass.hpp"
  48 #include "oops/objArrayOop.inline.hpp"
  49 #include "oops/oop.inline.hpp"
  50 #include "oops/symbol.hpp"




  51 #include "prims/jvmtiExport.hpp"
  52 #include "prims/nativeLookup.hpp"
  53 #include "runtime/atomic.hpp"
  54 #include "runtime/biasedLocking.hpp"
  55 #include "runtime/compilationPolicy.hpp"
  56 #include "runtime/deoptimization.hpp"
  57 #include "runtime/fieldDescriptor.inline.hpp"
  58 #include "runtime/frame.inline.hpp"
  59 #include "runtime/handles.inline.hpp"
  60 #include "runtime/icache.hpp"
  61 #include "runtime/interfaceSupport.inline.hpp"
  62 #include "runtime/java.hpp"
  63 #include "runtime/javaCalls.hpp"
  64 #include "runtime/jfieldIDWorkaround.hpp"
  65 #include "runtime/osThread.hpp"
  66 #include "runtime/sharedRuntime.hpp"
  67 #include "runtime/stubRoutines.hpp"
  68 #include "runtime/synchronizer.hpp"
  69 #include "runtime/threadCritical.hpp"
  70 #include "utilities/align.hpp"
  71 #include "utilities/copy.hpp"
  72 #include "utilities/events.hpp"

  73 #ifdef COMPILER2
  74 #include "opto/runtime.hpp"
  75 #endif
  76 
  77 class UnlockFlagSaver {
  78   private:
  79     JavaThread* _thread;
  80     bool _do_not_unlock;
  81   public:
  82     UnlockFlagSaver(JavaThread* t) {
  83       _thread = t;
  84       _do_not_unlock = t->do_not_unlock_if_synchronized();
  85       t->set_do_not_unlock_if_synchronized(false);
  86     }
  87     ~UnlockFlagSaver() {
  88       _thread->set_do_not_unlock_if_synchronized(_do_not_unlock);
  89     }
  90 };
  91 
  92 // Helper class to access current interpreter state


 237   klass->initialize(CHECK);
 238 
 239   // At this point the class may not be fully initialized
 240   // because of recursive initialization. If it is fully
 241   // initialized & has_finalized is not set, we rewrite
 242   // it into its fast version (Note: no locking is needed
 243   // here since this is an atomic byte write and can be
 244   // done more than once).
 245   //
 246   // Note: In case of classes with has_finalized we don't
 247   //       rewrite since that saves us an extra check in
 248   //       the fast version which then would call the
 249   //       slow version anyway (and do a call back into
 250   //       Java).
 251   //       If we have a breakpoint, then we don't rewrite
 252   //       because the _breakpoint bytecode would be lost.
 253   oop obj = klass->allocate_instance(CHECK);
 254   thread->set_vm_result(obj);
 255 JRT_END
 256 





























































































































































































 257 
 258 JRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* thread, BasicType type, jint size))
 259   oop obj = oopFactory::new_typeArray(type, size, CHECK);
 260   thread->set_vm_result(obj);
 261 JRT_END
 262 
 263 
 264 JRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* thread, ConstantPool* pool, int index, jint size))
 265   Klass*    klass = pool->klass_at(index, CHECK);
 266   objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);







 267   thread->set_vm_result(obj);
 268 JRT_END
 269 



































 270 
 271 JRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* thread, jint* first_size_address))
 272   // We may want to pass in more arguments - could make this slightly faster
 273   LastFrameAccessor last_frame(thread);
 274   ConstantPool* constants = last_frame.method()->constants();
 275   int          i = last_frame.get_index_u2(Bytecodes::_multianewarray);
 276   Klass* klass   = constants->klass_at(i, CHECK);

 277   int   nof_dims = last_frame.number_of_dimensions();
 278   assert(klass->is_klass(), "not a class");
 279   assert(nof_dims >= 1, "multianewarray rank must be nonzero");
 280 




 281   // We must create an array of jints to pass to multi_allocate.
 282   ResourceMark rm(thread);
 283   const int small_dims = 10;
 284   jint dim_array[small_dims];
 285   jint *dims = &dim_array[0];
 286   if (nof_dims > small_dims) {
 287     dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
 288   }
 289   for (int index = 0; index < nof_dims; index++) {
 290     // offset from first_size_address is addressed as local[index]
 291     int n = Interpreter::local_offset_in_bytes(index)/jintSize;
 292     dims[index] = first_size_address[n];
 293   }
 294   oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
 295   thread->set_vm_result(obj);
 296 JRT_END
 297 
 298 
 299 JRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* thread, oopDesc* obj))
 300   assert(oopDesc::is_oop(obj), "must be a valid oop");
 301   assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
 302   InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
 303 JRT_END
 304 














 305 
 306 // Quicken instance-of and check-cast bytecodes
 307 JRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* thread))
 308   // Force resolving; quicken the bytecode
 309   LastFrameAccessor last_frame(thread);
 310   int which = last_frame.get_index_u2(Bytecodes::_checkcast);
 311   ConstantPool* cpool = last_frame.method()->constants();
 312   // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
 313   // program we might have seen an unquick'd bytecode in the interpreter but have another
 314   // thread quicken the bytecode before we get here.
 315   // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
 316   Klass* klass = cpool->klass_at(which, CHECK);
 317   thread->set_vm_result_2(klass);
 318 JRT_END
 319 
 320 
 321 //------------------------------------------------------------------------------------------------------------------------
 322 // Exceptions
 323 
 324 void InterpreterRuntime::note_trap_inner(JavaThread* thread, int reason,


 671   buf[0] = '\0';
 672   jio_snprintf(buf, sizeof(buf),
 673                "Class %s does not implement the requested interface %s",
 674                recvKlass ? recvKlass->external_name() : "NULL",
 675                interfaceKlass ? interfaceKlass->external_name() : "NULL");
 676   THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
 677 JRT_END
 678 
 679 //------------------------------------------------------------------------------------------------------------------------
 680 // Fields
 681 //
 682 
 683 void InterpreterRuntime::resolve_get_put(JavaThread* thread, Bytecodes::Code bytecode) {
 684   Thread* THREAD = thread;
 685   // resolve field
 686   fieldDescriptor info;
 687   LastFrameAccessor last_frame(thread);
 688   constantPoolHandle pool(thread, last_frame.method()->constants());
 689   methodHandle m(thread, last_frame.method());
 690   bool is_put    = (bytecode == Bytecodes::_putfield  || bytecode == Bytecodes::_nofast_putfield ||
 691                     bytecode == Bytecodes::_putstatic);
 692   bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic);

 693 
 694   {
 695     JvmtiHideSingleStepping jhss(thread);
 696     LinkResolver::resolve_field_access(info, pool, last_frame.get_index_u2_cpcache(bytecode),
 697                                        m, bytecode, CHECK);
 698   } // end JvmtiHideSingleStepping
 699 
 700   // check if link resolution caused cpCache to be updated
 701   ConstantPoolCacheEntry* cp_cache_entry = last_frame.cache_entry();
 702   if (cp_cache_entry->is_resolved(bytecode)) return;
 703 
 704   // compute auxiliary field attributes
 705   TosState state  = as_TosState(info.field_type());
 706 
 707   // Resolution of put instructions on final fields is delayed. That is required so that
 708   // exceptions are thrown at the correct place (when the instruction is actually invoked).
 709   // If we do not resolve an instruction in the current pass, leaving the put_code
 710   // set to zero will cause the next put instruction to the same field to reresolve.
 711 
 712   // Resolution of put instructions to final instance fields with invalid updates (i.e.,


 716   // initializer method <init>. If resolution were not inhibited, a putfield
 717   // in an initializer method could be resolved in the initializer. Subsequent
 718   // putfield instructions to the same field would then use cached information.
 719   // As a result, those instructions would not pass through the VM. That is,
 720   // checks in resolve_field_access() would not be executed for those instructions
 721   // and the required IllegalAccessError would not be thrown.
 722   //
 723   // Also, we need to delay resolving getstatic and putstatic instructions until the
 724   // class is initialized.  This is required so that access to the static
 725   // field will call the initialization function every time until the class
 726   // is completely initialized ala. in 2.17.5 in JVM Specification.
 727   InstanceKlass* klass = info.field_holder();
 728   bool uninitialized_static = is_static && !klass->is_initialized();
 729   bool has_initialized_final_update = info.field_holder()->major_version() >= 53 &&
 730                                       info.has_initialized_final_update();
 731   assert(!(has_initialized_final_update && !info.access_flags().is_final()), "Fields with initialized final updates must be final");
 732 
 733   Bytecodes::Code get_code = (Bytecodes::Code)0;
 734   Bytecodes::Code put_code = (Bytecodes::Code)0;
 735   if (!uninitialized_static) {
 736     get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield);
 737     if ((is_put && !has_initialized_final_update) || !info.access_flags().is_final()) {
 738       put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);






 739     }
 740   }
 741 
 742   cp_cache_entry->set_field(
 743     get_code,
 744     put_code,
 745     info.field_holder(),
 746     info.index(),
 747     info.offset(),
 748     state,
 749     info.access_flags().is_final(),
 750     info.access_flags().is_volatile(),


 751     pool->pool_holder()
 752   );
 753 }
 754 
 755 
 756 //------------------------------------------------------------------------------------------------------------------------
 757 // Synchronization
 758 //
 759 // The interpreter's synchronization code is factored out so that it can
 760 // be shared by method invocation and synchronized blocks.
 761 //%note synchronization_3
 762 
 763 //%note monitor_1
 764 JRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* thread, BasicObjectLock* elem))
 765 #ifdef ASSERT
 766   thread->last_frame().interpreter_frame_verify_monitor(elem);
 767 #endif
 768   if (PrintBiasedLockingStatistics) {
 769     Atomic::inc(BiasedLocking::slow_path_entry_count_addr());
 770   }


 841   method->set_orig_bytecode_at(method->bci_from(bcp), new_code);
 842 JRT_END
 843 
 844 JRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* thread, Method* method, address bcp))
 845   JvmtiExport::post_raw_breakpoint(thread, method, bcp);
 846 JRT_END
 847 
 848 void InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode) {
 849   Thread* THREAD = thread;
 850   LastFrameAccessor last_frame(thread);
 851   // extract receiver from the outgoing argument list if necessary
 852   Handle receiver(thread, NULL);
 853   if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface ||
 854       bytecode == Bytecodes::_invokespecial) {
 855     ResourceMark rm(thread);
 856     methodHandle m (thread, last_frame.method());
 857     Bytecode_invoke call(m, last_frame.bci());
 858     Symbol* signature = call.signature();
 859     receiver = Handle(thread, last_frame.callee_receiver(signature));
 860 
 861     assert(Universe::heap()->is_in_reserved_or_null(receiver()),
 862            "sanity check");
 863     assert(receiver.is_null() ||
 864            !Universe::heap()->is_in_reserved(receiver->klass()),
 865            "sanity check");
 866   }
 867 
 868   // resolve method
 869   CallInfo info;
 870   constantPoolHandle pool(thread, last_frame.method()->constants());
 871 
 872   {
 873     JvmtiHideSingleStepping jhss(thread);
 874     LinkResolver::resolve_invoke(info, receiver, pool,
 875                                  last_frame.get_index_u2_cpcache(bytecode), bytecode,
 876                                  CHECK);
 877     if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
 878       int retry_count = 0;
 879       while (info.resolved_method()->is_old()) {
 880         // It is very unlikely that method is redefined more than 100 times
 881         // in the middle of resolve. If it is looping here more than 100 times
 882         // means then there could be a bug here.


 984   int index = last_frame.get_index_u4(bytecode);
 985   {
 986     JvmtiHideSingleStepping jhss(thread);
 987     LinkResolver::resolve_invoke(info, Handle(), pool,
 988                                  index, bytecode, CHECK);
 989   } // end JvmtiHideSingleStepping
 990 
 991   ConstantPoolCacheEntry* cp_cache_entry = pool->invokedynamic_cp_cache_entry_at(index);
 992   cp_cache_entry->set_dynamic_call(pool, info);
 993 }
 994 
 995 // This function is the interface to the assembly code. It returns the resolved
 996 // cpCache entry.  This doesn't safepoint, but the helper routines safepoint.
 997 // This function will check for redefinition!
 998 JRT_ENTRY(void, InterpreterRuntime::resolve_from_cache(JavaThread* thread, Bytecodes::Code bytecode)) {
 999   switch (bytecode) {
1000   case Bytecodes::_getstatic:
1001   case Bytecodes::_putstatic:
1002   case Bytecodes::_getfield:
1003   case Bytecodes::_putfield:

1004     resolve_get_put(thread, bytecode);
1005     break;
1006   case Bytecodes::_invokevirtual:
1007   case Bytecodes::_invokespecial:
1008   case Bytecodes::_invokestatic:
1009   case Bytecodes::_invokeinterface:
1010     resolve_invoke(thread, bytecode);
1011     break;
1012   case Bytecodes::_invokehandle:
1013     resolve_invokehandle(thread);
1014     break;
1015   case Bytecodes::_invokedynamic:
1016     resolve_invokedynamic(thread);
1017     break;
1018   default:
1019     fatal("unexpected bytecode: %s", Bytecodes::name(bytecode));
1020     break;
1021   }
1022 }
1023 JRT_END


1248   // check the access_flags for the field in the klass
1249   InstanceKlass* ik = InstanceKlass::cast(k);
1250   int index = cp_entry->field_index();
1251   // bail out if field modifications are not watched
1252   if ((ik->field_access_flags(index) & JVM_ACC_FIELD_MODIFICATION_WATCHED) == 0) return;
1253 
1254   char sig_type = '\0';
1255 
1256   switch(cp_entry->flag_state()) {
1257     case btos: sig_type = 'B'; break;
1258     case ztos: sig_type = 'Z'; break;
1259     case ctos: sig_type = 'C'; break;
1260     case stos: sig_type = 'S'; break;
1261     case itos: sig_type = 'I'; break;
1262     case ftos: sig_type = 'F'; break;
1263     case atos: sig_type = 'L'; break;
1264     case ltos: sig_type = 'J'; break;
1265     case dtos: sig_type = 'D'; break;
1266     default:  ShouldNotReachHere(); return;
1267   }






1268   bool is_static = (obj == NULL);
1269 
1270   HandleMark hm(thread);
1271   jfieldID fid = jfieldIDWorkaround::to_jfieldID(ik, cp_entry->f2_as_index(), is_static);
1272   jvalue fvalue;
1273 #ifdef _LP64
1274   fvalue = *value;
1275 #else
1276   // Long/double values are stored unaligned and also noncontiguously with
1277   // tagged stacks.  We can't just do a simple assignment even in the non-
1278   // J/D cases because a C++ compiler is allowed to assume that a jvalue is
1279   // 8-byte aligned, and interpreter stack slots are only 4-byte aligned.
1280   // We assume that the two halves of longs/doubles are stored in interpreter
1281   // stack slots in platform-endian order.
1282   jlong_accessor u;
1283   jint* newval = (jint*)value;
1284   u.words[0] = newval[0];
1285   u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
1286   fvalue.j = u.long_value;
1287 #endif // _LP64




  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/interpreter.hpp"
  36 #include "interpreter/interpreterRuntime.hpp"
  37 #include "interpreter/linkResolver.hpp"
  38 #include "interpreter/templateTable.hpp"
  39 #include "logging/log.hpp"
  40 #include "memory/oopFactory.hpp"
  41 #include "memory/resourceArea.hpp"
  42 #include "memory/universe.hpp"
  43 #include "oops/constantPool.hpp"
  44 #include "oops/cpCache.inline.hpp"
  45 #include "oops/instanceKlass.hpp"
  46 #include "oops/methodData.hpp"
  47 #include "oops/objArrayKlass.hpp"
  48 #include "oops/objArrayOop.inline.hpp"
  49 #include "oops/oop.inline.hpp"
  50 #include "oops/symbol.hpp"
  51 #include "oops/valueKlass.hpp"
  52 #include "oops/valueArrayKlass.hpp"
  53 #include "oops/valueArrayOop.hpp"
  54 #include "oops/valueArrayOop.inline.hpp"
  55 #include "prims/jvmtiExport.hpp"
  56 #include "prims/nativeLookup.hpp"
  57 #include "runtime/atomic.hpp"
  58 #include "runtime/biasedLocking.hpp"
  59 #include "runtime/compilationPolicy.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/stubRoutines.hpp"
  72 #include "runtime/synchronizer.hpp"
  73 #include "runtime/threadCritical.hpp"
  74 #include "utilities/align.hpp"
  75 #include "utilities/copy.hpp"
  76 #include "utilities/events.hpp"
  77 #include "utilities/globalDefinitions.hpp"
  78 #ifdef COMPILER2
  79 #include "opto/runtime.hpp"
  80 #endif
  81 
  82 class UnlockFlagSaver {
  83   private:
  84     JavaThread* _thread;
  85     bool _do_not_unlock;
  86   public:
  87     UnlockFlagSaver(JavaThread* t) {
  88       _thread = t;
  89       _do_not_unlock = t->do_not_unlock_if_synchronized();
  90       t->set_do_not_unlock_if_synchronized(false);
  91     }
  92     ~UnlockFlagSaver() {
  93       _thread->set_do_not_unlock_if_synchronized(_do_not_unlock);
  94     }
  95 };
  96 
  97 // Helper class to access current interpreter state


 242   klass->initialize(CHECK);
 243 
 244   // At this point the class may not be fully initialized
 245   // because of recursive initialization. If it is fully
 246   // initialized & has_finalized is not set, we rewrite
 247   // it into its fast version (Note: no locking is needed
 248   // here since this is an atomic byte write and can be
 249   // done more than once).
 250   //
 251   // Note: In case of classes with has_finalized we don't
 252   //       rewrite since that saves us an extra check in
 253   //       the fast version which then would call the
 254   //       slow version anyway (and do a call back into
 255   //       Java).
 256   //       If we have a breakpoint, then we don't rewrite
 257   //       because the _breakpoint bytecode would be lost.
 258   oop obj = klass->allocate_instance(CHECK);
 259   thread->set_vm_result(obj);
 260 JRT_END
 261 
 262 void copy_primitive_argument(intptr_t* addr, Handle instance, int offset, BasicType type) {
 263   switch (type) {
 264   case T_BOOLEAN:
 265     instance()->bool_field_put(offset, (jboolean)*((int*)addr));
 266     break;
 267   case T_CHAR:
 268     instance()->char_field_put(offset, (jchar) *((int*)addr));
 269     break;
 270   case T_FLOAT:
 271     instance()->float_field_put(offset, (jfloat)*((float*)addr));
 272     break;
 273   case T_DOUBLE:
 274     instance()->double_field_put(offset, (jdouble)*((double*)addr));
 275     break;
 276   case T_BYTE:
 277     instance()->byte_field_put(offset, (jbyte)*((int*)addr));
 278     break;
 279   case T_SHORT:
 280     instance()->short_field_put(offset, (jshort)*((int*)addr));
 281     break;
 282   case T_INT:
 283     instance()->int_field_put(offset, (jint)*((int*)addr));
 284     break;
 285   case T_LONG:
 286     instance()->long_field_put(offset, (jlong)*((long long*)addr));
 287     break;
 288   case T_OBJECT:
 289   case T_ARRAY:
 290   case T_VALUETYPE:
 291     fatal("Should not be handled with this method");
 292     break;
 293   default:
 294     fatal("Unsupported BasicType");
 295   }
 296 }
 297 
 298 JRT_ENTRY(void, InterpreterRuntime::defaultvalue(JavaThread* thread, ConstantPool* pool, int index))
 299   // Getting the ValueKlass
 300   Klass* k = pool->klass_at(index, CHECK);
 301   assert(k->is_value(), "defaultvalue argument must be the value type class");
 302   ValueKlass* vklass = ValueKlass::cast(k);
 303 
 304   vklass->initialize(THREAD);
 305   oop res = vklass->default_value();
 306   thread->set_vm_result(res);
 307 JRT_END
 308 
 309 JRT_ENTRY(int, InterpreterRuntime::withfield(JavaThread* thread, ConstantPoolCache* cp_cache))
 310   LastFrameAccessor last_frame(thread);
 311   // Getting the ValueKlass
 312   int index = ConstantPool::decode_cpcache_index(last_frame.get_index_u2_cpcache(Bytecodes::_withfield));
 313   ConstantPoolCacheEntry* cp_entry = cp_cache->entry_at(index);
 314   assert(cp_entry->is_resolved(Bytecodes::_withfield), "Should have been resolved");
 315   Klass* klass = cp_entry->f1_as_klass();
 316   assert(klass->is_value(), "withfield only applies to value types");
 317   ValueKlass* vklass = ValueKlass::cast(klass);
 318 
 319   // Getting Field information
 320   int offset = cp_entry->f2_as_index();
 321   int field_index = cp_entry->field_index();
 322   int field_offset = cp_entry->f2_as_offset();
 323   Symbol* field_signature = vklass->field_signature(field_index);
 324   ResourceMark rm(THREAD);
 325   const char* signature = (const char *) field_signature->as_utf8();
 326   BasicType field_type = char2type(signature[0]);
 327 
 328   // Getting old value
 329   frame& f = last_frame.get_frame();
 330   jint tos_idx = f.interpreter_frame_expression_stack_size() - 1;
 331   int vt_offset = type2size[field_type];
 332   oop old_value = *(oop*)f.interpreter_frame_expression_stack_at(tos_idx - vt_offset);
 333   assert(old_value != NULL && oopDesc::is_oop(old_value) && old_value->is_value(),"Verifying receiver");
 334   Handle old_value_h(THREAD, old_value);
 335 
 336   // Creating new value by copying the one passed in argument
 337   instanceOop new_value = vklass->allocate_instance(
 338       CHECK_((type2size[field_type]) * AbstractInterpreter::stackElementSize));
 339   Handle new_value_h = Handle(THREAD, new_value);
 340   int first_offset = vklass->first_field_offset();
 341   vklass->value_store(vklass->data_for_oop(old_value_h()),
 342       vklass->data_for_oop(new_value_h()), true, false);
 343 
 344   // Updating the field specified in arguments
 345   if (field_type == T_ARRAY || field_type == T_OBJECT) {
 346     oop aoop = *(oop*)f.interpreter_frame_expression_stack_at(tos_idx);
 347     assert(aoop == NULL || oopDesc::is_oop(aoop),"argument must be a reference type");
 348     new_value_h()->obj_field_put(field_offset, aoop);
 349   } else if (field_type == T_VALUETYPE) {
 350     if (cp_entry->is_flattened()) {
 351       oop vt_oop = *(oop*)f.interpreter_frame_expression_stack_at(tos_idx);
 352       if (vt_oop == NULL) {
 353         THROW_(vmSymbols::java_lang_NullPointerException(),
 354             (type2size[field_type] * AbstractInterpreter::stackElementSize));
 355       }
 356       assert(vt_oop != NULL && oopDesc::is_oop(vt_oop) && vt_oop->is_value(),"argument must be a value type");
 357       Klass* field_k = vklass->get_value_field_klass(field_index);
 358       ValueKlass* field_vk = ValueKlass::cast(field_k);
 359       assert(field_vk == vt_oop->klass(), "Must match");
 360       field_vk->value_store(field_vk->data_for_oop(vt_oop),
 361           ((char*)(oopDesc*)new_value_h()) + field_offset, false, false);
 362     } else { // not flattened
 363       oop voop = *(oop*)f.interpreter_frame_expression_stack_at(tos_idx);
 364       if (voop == NULL && cp_entry->is_flattenable()) {
 365         THROW_(vmSymbols::java_lang_NullPointerException(),
 366             (type2size[field_type] * AbstractInterpreter::stackElementSize));
 367       }
 368       assert(voop == NULL || oopDesc::is_oop(voop),"checking argument");
 369       new_value_h()->obj_field_put(field_offset, voop);
 370     }
 371   } else { // not T_OBJECT nor T_ARRAY nor T_VALUETYPE
 372     intptr_t* addr = f.interpreter_frame_expression_stack_at(tos_idx);
 373     copy_primitive_argument(addr, new_value_h, field_offset, field_type);
 374   }
 375 
 376   // returning result
 377   thread->set_vm_result(new_value_h());
 378   return (type2size[field_type] + type2size[T_OBJECT]) * AbstractInterpreter::stackElementSize;
 379 JRT_END
 380 
 381 JRT_ENTRY(void, InterpreterRuntime::uninitialized_static_value_field(JavaThread* thread, oopDesc* mirror, int index))
 382   // The interpreter tries to access a flattenable static field that has not been initialized.
 383   // This situation can happen only if the load or initialization of the field failed during step 8 of
 384   // the initialization of the holder of the field. The code below tries to load and initialize
 385   // the field's class again in order to throw likely the same exception or error as the one that caused
 386   // the field initialization to fail.
 387   instanceHandle mirror_h(THREAD, (instanceOop)mirror);
 388   InstanceKlass* klass = InstanceKlass::cast(java_lang_Class::as_Klass(mirror));
 389   int offset = klass->field_offset(index);
 390   Klass* field_k = klass->get_value_field_klass_or_null(index);
 391   if (field_k == NULL) {
 392     field_k = SystemDictionary::resolve_or_fail(klass->field_signature(index)->fundamental_name(THREAD),
 393         Handle(THREAD, klass->class_loader()),
 394         Handle(THREAD, klass->protection_domain()),
 395         true, CHECK);
 396     assert(field_k != NULL, "Should have been loaded or an exception thrown above");
 397     klass->set_value_field_klass(index, field_k);
 398   }
 399   field_k->initialize(CHECK);
 400   fatal("An exception should have been thrown above");
 401 JRT_END
 402 
 403 JRT_ENTRY(void, InterpreterRuntime::uninitialized_instance_value_field(JavaThread* thread, oopDesc* obj, int index))
 404   instanceHandle obj_h(THREAD, (instanceOop)obj);
 405   InstanceKlass* klass = InstanceKlass::cast(obj_h()->klass());
 406   Klass* field_k = klass->get_value_field_klass_or_null(index);
 407   assert(field_k != NULL, "Must have been initialized");
 408   ValueKlass* field_vklass = ValueKlass::cast(field_k);
 409   assert(field_vklass->is_initialized(), "Must have been initialized at this point");
 410   instanceOop res = (instanceOop)field_vklass->default_value();
 411   thread->set_vm_result(res);
 412 JRT_END
 413 
 414 JRT_ENTRY(void, InterpreterRuntime::write_flattened_value(JavaThread* thread, oopDesc* value, int offset, oopDesc* rcv))
 415   assert(oopDesc::is_oop(value), "Sanity check");
 416   assert(oopDesc::is_oop(rcv), "Sanity check");
 417   assert(value->is_value(), "Sanity check");
 418 
 419   ValueKlass* vklass = ValueKlass::cast(value->klass());
 420   if (!vklass->is_empty_value()) {
 421     vklass->value_store(vklass->data_for_oop(value), ((char*)(oopDesc*)rcv) + offset, true, true);
 422   }
 423 JRT_END
 424 
 425 JRT_ENTRY(void, InterpreterRuntime::read_flattened_field(JavaThread* thread, oopDesc* obj, int index, Klass* field_holder))
 426   Handle obj_h(THREAD, obj);
 427 
 428   assert(oopDesc::is_oop(obj), "Sanity check");
 429 
 430   assert(field_holder->is_instance_klass(), "Sanity check");
 431   InstanceKlass* klass = InstanceKlass::cast(field_holder);
 432 
 433   assert(klass->field_is_flattened(index), "Sanity check");
 434 
 435   ValueKlass* field_vklass = ValueKlass::cast(klass->get_value_field_klass(index));
 436   assert(field_vklass->is_initialized(), "Must be initialized at this point");
 437 
 438   instanceOop res = NULL;
 439   if (field_vklass->is_empty_value()) {
 440     res = (instanceOop)field_vklass->default_value();
 441   } else {
 442     // allocate instance
 443     res = field_vklass->allocate_instance(CHECK);
 444     // copy value
 445     field_vklass->value_store(((char*)(oopDesc*)obj_h()) + klass->field_offset(index),
 446         field_vklass->data_for_oop(res), true, true);
 447   }
 448   assert(res != NULL, "Must be set in one of two paths above");
 449   thread->set_vm_result(res);
 450 JRT_END
 451 
 452 JRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* thread, BasicType type, jint size))
 453   oop obj = oopFactory::new_typeArray(type, size, CHECK);
 454   thread->set_vm_result(obj);
 455 JRT_END
 456 
 457 
 458 JRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* thread, ConstantPool* pool, int index, jint size))
 459   Klass*    klass = pool->klass_at(index, CHECK);
 460   bool      is_qtype_desc = pool->tag_at(index).is_Qdescriptor_klass();
 461   arrayOop obj;
 462   if ((!klass->is_array_klass()) && is_qtype_desc) { // Logically creates elements, ensure klass init
 463     klass->initialize(CHECK);
 464     obj = oopFactory::new_valueArray(klass, size, CHECK);
 465   } else {
 466     obj = oopFactory::new_objArray(klass, size, CHECK);
 467   }
 468   thread->set_vm_result(obj);
 469 JRT_END
 470 
 471 JRT_ENTRY(void, InterpreterRuntime::value_array_load(JavaThread* thread, arrayOopDesc* array, int index))
 472   Klass* klass = array->klass();
 473   assert(klass->is_valueArray_klass(), "expected value array oop");
 474 
 475   ValueArrayKlass* vaklass = ValueArrayKlass::cast(klass);
 476   ValueKlass* vklass = vaklass->element_klass();
 477   arrayHandle ah(THREAD, array);
 478   instanceOop value_holder = NULL;
 479   if (vklass->is_empty_value()) {
 480     value_holder = (instanceOop)vklass->default_value();
 481   } else {
 482     value_holder = vklass->allocate_instance(CHECK);
 483     void* src = ((valueArrayOop)ah())->value_at_addr(index, vaklass->layout_helper());
 484     vklass->value_store(src, vklass->data_for_oop(value_holder),
 485         vaklass->element_byte_size(), true, false);
 486   }
 487   assert(value_holder != NULL, "Must be set in one of two paths above");
 488   thread->set_vm_result(value_holder);
 489 JRT_END
 490 
 491 JRT_ENTRY(void, InterpreterRuntime::value_array_store(JavaThread* thread, void* val, arrayOopDesc* array, int index))
 492   assert(val != NULL, "can't store null into flat array");
 493   Klass* klass = array->klass();
 494   assert(klass->is_valueArray_klass(), "expected value array");
 495   assert(ArrayKlass::cast(klass)->element_klass() == ((oop)val)->klass(), "Store type incorrect");
 496 
 497   valueArrayOop varray = (valueArrayOop)array;
 498   ValueArrayKlass* vaklass = ValueArrayKlass::cast(klass);
 499   ValueKlass* vklass = vaklass->element_klass();
 500   if (!vklass->is_empty_value()) {
 501     const int lh = vaklass->layout_helper();
 502     vklass->value_store(vklass->data_for_oop((oop)val), varray->value_at_addr(index, lh),
 503         vaklass->element_byte_size(), true, false);
 504   }
 505 JRT_END
 506 
 507 JRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* thread, jint* first_size_address))
 508   // We may want to pass in more arguments - could make this slightly faster
 509   LastFrameAccessor last_frame(thread);
 510   ConstantPool* constants = last_frame.method()->constants();
 511   int i = last_frame.get_index_u2(Bytecodes::_multianewarray);
 512   Klass* klass = constants->klass_at(i, CHECK);
 513   bool is_qtype = klass->name()->is_Q_array_signature();
 514   int   nof_dims = last_frame.number_of_dimensions();
 515   assert(klass->is_klass(), "not a class");
 516   assert(nof_dims >= 1, "multianewarray rank must be nonzero");
 517 
 518   if (is_qtype) { // Logically creates elements, ensure klass init
 519     klass->initialize(CHECK);
 520   }
 521 
 522   // We must create an array of jints to pass to multi_allocate.
 523   ResourceMark rm(thread);
 524   const int small_dims = 10;
 525   jint dim_array[small_dims];
 526   jint *dims = &dim_array[0];
 527   if (nof_dims > small_dims) {
 528     dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
 529   }
 530   for (int index = 0; index < nof_dims; index++) {
 531     // offset from first_size_address is addressed as local[index]
 532     int n = Interpreter::local_offset_in_bytes(index)/jintSize;
 533     dims[index] = first_size_address[n];
 534   }
 535   oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
 536   thread->set_vm_result(obj);
 537 JRT_END
 538 
 539 
 540 JRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* thread, oopDesc* obj))
 541   assert(oopDesc::is_oop(obj), "must be a valid oop");
 542   assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
 543   InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
 544 JRT_END
 545 
 546 JRT_ENTRY(jboolean, InterpreterRuntime::is_substitutable(JavaThread* thread, oopDesc* aobj, oopDesc* bobj))
 547   assert(oopDesc::is_oop(aobj) && oopDesc::is_oop(bobj), "must be valid oops");
 548 
 549   Handle ha(THREAD, aobj);
 550   Handle hb(THREAD, bobj);
 551   JavaValue result(T_BOOLEAN);
 552   JavaCallArguments args;
 553   args.push_oop(ha);
 554   args.push_oop(hb);
 555   methodHandle method(Universe::is_substitutable_method());
 556   JavaCalls::call(&result, method, &args, THREAD);
 557   guarantee(!HAS_PENDING_EXCEPTION, "isSubstitutable() raised exception");
 558   return result.get_jboolean();
 559 JRT_END
 560 
 561 // Quicken instance-of and check-cast bytecodes
 562 JRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* thread))
 563   // Force resolving; quicken the bytecode
 564   LastFrameAccessor last_frame(thread);
 565   int which = last_frame.get_index_u2(Bytecodes::_checkcast);
 566   ConstantPool* cpool = last_frame.method()->constants();
 567   // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
 568   // program we might have seen an unquick'd bytecode in the interpreter but have another
 569   // thread quicken the bytecode before we get here.
 570   // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
 571   Klass* klass = cpool->klass_at(which, CHECK);
 572   thread->set_vm_result_2(klass);
 573 JRT_END
 574 
 575 
 576 //------------------------------------------------------------------------------------------------------------------------
 577 // Exceptions
 578 
 579 void InterpreterRuntime::note_trap_inner(JavaThread* thread, int reason,


 926   buf[0] = '\0';
 927   jio_snprintf(buf, sizeof(buf),
 928                "Class %s does not implement the requested interface %s",
 929                recvKlass ? recvKlass->external_name() : "NULL",
 930                interfaceKlass ? interfaceKlass->external_name() : "NULL");
 931   THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
 932 JRT_END
 933 
 934 //------------------------------------------------------------------------------------------------------------------------
 935 // Fields
 936 //
 937 
 938 void InterpreterRuntime::resolve_get_put(JavaThread* thread, Bytecodes::Code bytecode) {
 939   Thread* THREAD = thread;
 940   // resolve field
 941   fieldDescriptor info;
 942   LastFrameAccessor last_frame(thread);
 943   constantPoolHandle pool(thread, last_frame.method()->constants());
 944   methodHandle m(thread, last_frame.method());
 945   bool is_put    = (bytecode == Bytecodes::_putfield  || bytecode == Bytecodes::_nofast_putfield ||
 946                     bytecode == Bytecodes::_putstatic || bytecode == Bytecodes::_withfield);
 947   bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic);
 948   bool is_value  = bytecode == Bytecodes::_withfield;
 949 
 950   {
 951     JvmtiHideSingleStepping jhss(thread);
 952     LinkResolver::resolve_field_access(info, pool, last_frame.get_index_u2_cpcache(bytecode),
 953                                        m, bytecode, CHECK);
 954   } // end JvmtiHideSingleStepping
 955 
 956   // check if link resolution caused cpCache to be updated
 957   ConstantPoolCacheEntry* cp_cache_entry = last_frame.cache_entry();
 958   if (cp_cache_entry->is_resolved(bytecode)) return;
 959 
 960   // compute auxiliary field attributes
 961   TosState state  = as_TosState(info.field_type());
 962 
 963   // Resolution of put instructions on final fields is delayed. That is required so that
 964   // exceptions are thrown at the correct place (when the instruction is actually invoked).
 965   // If we do not resolve an instruction in the current pass, leaving the put_code
 966   // set to zero will cause the next put instruction to the same field to reresolve.
 967 
 968   // Resolution of put instructions to final instance fields with invalid updates (i.e.,


 972   // initializer method <init>. If resolution were not inhibited, a putfield
 973   // in an initializer method could be resolved in the initializer. Subsequent
 974   // putfield instructions to the same field would then use cached information.
 975   // As a result, those instructions would not pass through the VM. That is,
 976   // checks in resolve_field_access() would not be executed for those instructions
 977   // and the required IllegalAccessError would not be thrown.
 978   //
 979   // Also, we need to delay resolving getstatic and putstatic instructions until the
 980   // class is initialized.  This is required so that access to the static
 981   // field will call the initialization function every time until the class
 982   // is completely initialized ala. in 2.17.5 in JVM Specification.
 983   InstanceKlass* klass = info.field_holder();
 984   bool uninitialized_static = is_static && !klass->is_initialized();
 985   bool has_initialized_final_update = info.field_holder()->major_version() >= 53 &&
 986                                       info.has_initialized_final_update();
 987   assert(!(has_initialized_final_update && !info.access_flags().is_final()), "Fields with initialized final updates must be final");
 988 
 989   Bytecodes::Code get_code = (Bytecodes::Code)0;
 990   Bytecodes::Code put_code = (Bytecodes::Code)0;
 991   if (!uninitialized_static) {
 992     if (is_static) {
 993       get_code = Bytecodes::_getstatic;
 994     } else {
 995       get_code = Bytecodes::_getfield;
 996     }
 997     if (is_put && is_value) {
 998         put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_withfield);
 999     } else if ((is_put && !has_initialized_final_update) || !info.access_flags().is_final()) {
1000         put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
1001     }
1002   }
1003 
1004   cp_cache_entry->set_field(
1005     get_code,
1006     put_code,
1007     info.field_holder(),
1008     info.index(),
1009     info.offset(),
1010     state,
1011     info.access_flags().is_final(),
1012     info.access_flags().is_volatile(),
1013     info.is_flattened(),
1014     info.is_flattenable(),
1015     pool->pool_holder()
1016   );
1017 }
1018 
1019 
1020 //------------------------------------------------------------------------------------------------------------------------
1021 // Synchronization
1022 //
1023 // The interpreter's synchronization code is factored out so that it can
1024 // be shared by method invocation and synchronized blocks.
1025 //%note synchronization_3
1026 
1027 //%note monitor_1
1028 JRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* thread, BasicObjectLock* elem))
1029 #ifdef ASSERT
1030   thread->last_frame().interpreter_frame_verify_monitor(elem);
1031 #endif
1032   if (PrintBiasedLockingStatistics) {
1033     Atomic::inc(BiasedLocking::slow_path_entry_count_addr());
1034   }


1105   method->set_orig_bytecode_at(method->bci_from(bcp), new_code);
1106 JRT_END
1107 
1108 JRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* thread, Method* method, address bcp))
1109   JvmtiExport::post_raw_breakpoint(thread, method, bcp);
1110 JRT_END
1111 
1112 void InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode) {
1113   Thread* THREAD = thread;
1114   LastFrameAccessor last_frame(thread);
1115   // extract receiver from the outgoing argument list if necessary
1116   Handle receiver(thread, NULL);
1117   if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface ||
1118       bytecode == Bytecodes::_invokespecial) {
1119     ResourceMark rm(thread);
1120     methodHandle m (thread, last_frame.method());
1121     Bytecode_invoke call(m, last_frame.bci());
1122     Symbol* signature = call.signature();
1123     receiver = Handle(thread, last_frame.callee_receiver(signature));
1124 
1125     assert(Universe::heap()->is_in_reserved_or_null(receiver()), "sanity check");

1126     assert(receiver.is_null() ||
1127            !Universe::heap()->is_in_reserved(receiver->klass()),
1128            "sanity check");
1129   }
1130 
1131   // resolve method
1132   CallInfo info;
1133   constantPoolHandle pool(thread, last_frame.method()->constants());
1134 
1135   {
1136     JvmtiHideSingleStepping jhss(thread);
1137     LinkResolver::resolve_invoke(info, receiver, pool,
1138                                  last_frame.get_index_u2_cpcache(bytecode), bytecode,
1139                                  CHECK);
1140     if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
1141       int retry_count = 0;
1142       while (info.resolved_method()->is_old()) {
1143         // It is very unlikely that method is redefined more than 100 times
1144         // in the middle of resolve. If it is looping here more than 100 times
1145         // means then there could be a bug here.


1247   int index = last_frame.get_index_u4(bytecode);
1248   {
1249     JvmtiHideSingleStepping jhss(thread);
1250     LinkResolver::resolve_invoke(info, Handle(), pool,
1251                                  index, bytecode, CHECK);
1252   } // end JvmtiHideSingleStepping
1253 
1254   ConstantPoolCacheEntry* cp_cache_entry = pool->invokedynamic_cp_cache_entry_at(index);
1255   cp_cache_entry->set_dynamic_call(pool, info);
1256 }
1257 
1258 // This function is the interface to the assembly code. It returns the resolved
1259 // cpCache entry.  This doesn't safepoint, but the helper routines safepoint.
1260 // This function will check for redefinition!
1261 JRT_ENTRY(void, InterpreterRuntime::resolve_from_cache(JavaThread* thread, Bytecodes::Code bytecode)) {
1262   switch (bytecode) {
1263   case Bytecodes::_getstatic:
1264   case Bytecodes::_putstatic:
1265   case Bytecodes::_getfield:
1266   case Bytecodes::_putfield:
1267   case Bytecodes::_withfield:
1268     resolve_get_put(thread, bytecode);
1269     break;
1270   case Bytecodes::_invokevirtual:
1271   case Bytecodes::_invokespecial:
1272   case Bytecodes::_invokestatic:
1273   case Bytecodes::_invokeinterface:
1274     resolve_invoke(thread, bytecode);
1275     break;
1276   case Bytecodes::_invokehandle:
1277     resolve_invokehandle(thread);
1278     break;
1279   case Bytecodes::_invokedynamic:
1280     resolve_invokedynamic(thread);
1281     break;
1282   default:
1283     fatal("unexpected bytecode: %s", Bytecodes::name(bytecode));
1284     break;
1285   }
1286 }
1287 JRT_END


1512   // check the access_flags for the field in the klass
1513   InstanceKlass* ik = InstanceKlass::cast(k);
1514   int index = cp_entry->field_index();
1515   // bail out if field modifications are not watched
1516   if ((ik->field_access_flags(index) & JVM_ACC_FIELD_MODIFICATION_WATCHED) == 0) return;
1517 
1518   char sig_type = '\0';
1519 
1520   switch(cp_entry->flag_state()) {
1521     case btos: sig_type = 'B'; break;
1522     case ztos: sig_type = 'Z'; break;
1523     case ctos: sig_type = 'C'; break;
1524     case stos: sig_type = 'S'; break;
1525     case itos: sig_type = 'I'; break;
1526     case ftos: sig_type = 'F'; break;
1527     case atos: sig_type = 'L'; break;
1528     case ltos: sig_type = 'J'; break;
1529     case dtos: sig_type = 'D'; break;
1530     default:  ShouldNotReachHere(); return;
1531   }
1532 
1533   // Both Q-signatures and L-signatures are mapped to atos
1534   if (cp_entry->flag_state() == atos && ik->field_signature(index)->is_Q_signature()) {
1535     sig_type = 'Q';
1536   }
1537 
1538   bool is_static = (obj == NULL);
1539 
1540   HandleMark hm(thread);
1541   jfieldID fid = jfieldIDWorkaround::to_jfieldID(ik, cp_entry->f2_as_index(), is_static);
1542   jvalue fvalue;
1543 #ifdef _LP64
1544   fvalue = *value;
1545 #else
1546   // Long/double values are stored unaligned and also noncontiguously with
1547   // tagged stacks.  We can't just do a simple assignment even in the non-
1548   // J/D cases because a C++ compiler is allowed to assume that a jvalue is
1549   // 8-byte aligned, and interpreter stack slots are only 4-byte aligned.
1550   // We assume that the two halves of longs/doubles are stored in interpreter
1551   // stack slots in platform-endian order.
1552   jlong_accessor u;
1553   jint* newval = (jint*)value;
1554   u.words[0] = newval[0];
1555   u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
1556   fvalue.j = u.long_value;
1557 #endif // _LP64


< prev index next >