< prev index next >

src/share/vm/interpreter/interpreterRuntime.cpp

Print this page




  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/javaClasses.inline.hpp"
  27 #include "classfile/systemDictionary.hpp"
  28 #include "classfile/vmSymbols.hpp"
  29 #include "code/codeCache.hpp"
  30 #include "compiler/compileBroker.hpp"
  31 #include "compiler/disassembler.hpp"
  32 #include "gc/shared/collectedHeap.hpp"
  33 #include "interpreter/interpreter.hpp"
  34 #include "interpreter/interpreterRuntime.hpp"
  35 #include "interpreter/linkResolver.hpp"
  36 #include "interpreter/templateTable.hpp"
  37 #include "logging/log.hpp"
  38 #include "memory/oopFactory.hpp"
  39 #include "memory/resourceArea.hpp"
  40 #include "memory/universe.inline.hpp"

  41 #include "oops/constantPool.hpp"
  42 #include "oops/instanceKlass.hpp"
  43 #include "oops/methodData.hpp"
  44 #include "oops/objArrayKlass.hpp"
  45 #include "oops/objArrayOop.inline.hpp"
  46 #include "oops/oop.inline.hpp"
  47 #include "oops/symbol.hpp"
  48 #include "oops/valueKlass.hpp"
  49 #include "oops/valueArrayKlass.hpp"
  50 #include "oops/valueArrayOop.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.hpp"
  58 #include "runtime/handles.inline.hpp"
  59 #include "runtime/icache.hpp"
  60 #include "runtime/interfaceSupport.hpp"


 176     break;
 177   case T_CHAR:
 178     instance()->char_field_put(offset, (jchar) *((int*)addr));
 179     break;
 180   case T_FLOAT:
 181     instance()->float_field_put(offset, (jfloat)*((float*)addr));
 182     break;
 183   case T_DOUBLE:
 184     instance()->double_field_put(offset, (jdouble)*((double*)addr));
 185     break;
 186   case T_BYTE:
 187     instance()->byte_field_put(offset, (jbyte)*((int*)addr));
 188     break;
 189   case T_SHORT:
 190     instance()->short_field_put(offset, (jshort)*((int*)addr));
 191     break;
 192   case T_INT:
 193     instance()->int_field_put(offset, (jint)*((int*)addr));
 194     break;
 195   case T_LONG:
 196     instance()->long_field_put(offset, (jlong)*((long*)addr)); // Is it correct on 32 and 64 bits?
 197     break;
 198   case T_OBJECT:
 199   case T_ARRAY:
 200   case T_VALUETYPE:
 201     fatal("Should not be handled with this method");
 202     break;
 203   default:
 204     fatal("Unsupported BasicType");
 205   }
 206 }
 207 
 208 IRT_ENTRY(void, InterpreterRuntime::vdefault(JavaThread* thread, ConstantPool* pool, int index))
 209   // Getting the ValueKlass
 210   Klass* k = pool->klass_at(index, CHECK);
 211   assert(k->is_value(), "vdefault argument must be the value type class");
 212   ValueKlass* vklass = ValueKlass::cast(k);
 213 
 214   vklass->initialize(THREAD);
 215 
 216   // Creating value
 217   instanceOop value = vklass->allocate_instance(CHECK);

 218   Handle value_h = Handle(THREAD, value);
 219 
 220   // Zeroing, already performed by allocate_instance() when allocating in the Java Heap
 221   // Might need to be performed manually for off-heap allocations
 222   // memset(((char*)(oopDesc*)value) + vklass_h->first_field_offset(), 0,
 223   //        vklass_h->size_helper() * wordSize - vklass_h->first_field_offset());
 224 
 225   thread->set_vm_result(value_h());
 226 IRT_END
 227 
 228 IRT_ENTRY(int, InterpreterRuntime::vwithfield(JavaThread* thread, ConstantPoolCache* cp_cache))
 229   // Getting the ValueKlass
 230   int index = ConstantPool::decode_cpcache_index(get_index_u2_cpcache(thread, Bytecodes::_vwithfield));
 231   ConstantPoolCacheEntry* cp_entry = cp_cache->entry_at(index);
 232   assert(cp_entry->is_resolved(Bytecodes::_vwithfield), "Should have been resolved");
 233   Klass* klass = cp_entry->f1_as_klass();
 234   assert(klass->is_value(), "vwithfield only applies to value types");
 235   ValueKlass* vklass = ValueKlass::cast(klass);
 236 
 237   // Getting Field information
 238   int offset = cp_entry->f2_as_index();
 239   fieldDescriptor fd;
 240   vklass->find_field_from_offset(offset, false, &fd);
 241   Symbol* field_signature = fd.signature();
 242   ResourceMark rm(THREAD);
 243   const char* signature = (const char *) field_signature->as_utf8();
 244   BasicType field_type = char2type(signature[0]);
 245 
 246   // Getting old value
 247   frame f = last_frame(thread);
 248   jint tos_idx = f.interpreter_frame_expression_stack_size() - 1;
 249   int vt_offset = type2size[field_type];
 250   oop old_value = *(oop*)f.interpreter_frame_expression_stack_at(tos_idx - vt_offset);
 251   assert(old_value != NULL && old_value->is_oop() && old_value->is_value(),"Verifying receiver");
 252   Handle old_value_h(THREAD, old_value);
 253 
 254   // Creating new value by copying the one passed in argument
 255   instanceOop new_value = vklass->allocate_instance(CHECK_0);


 256   Handle new_value_h = Handle(THREAD, new_value);
 257   int first_offset = vklass->first_field_offset();
 258   vklass->value_store(((char*)(oopDesc*)old_value_h()) + first_offset,
 259       ((char*)(oopDesc*)new_value_h()) + first_offset, true, false);
 260 
 261   // Updating the field specified in arguments
 262   if (field_type == T_OBJECT || field_type == T_ARRAY) {
 263     oop aoop = *(oop*)f.interpreter_frame_expression_stack_at(tos_idx);
 264     assert(aoop == NULL || (aoop->is_oop() && (!aoop->is_value())),"argument must be a reference type");
 265     new_value_h()->obj_field_put(fd.offset(), aoop);
 266   } else if (field_type == T_VALUETYPE) {
 267     Klass* field_k = vklass->get_value_field_klass(fd.index());
 268     ValueKlass* field_vk = ValueKlass::cast(field_k);
 269     oop vt_oop = *(oop*)f.interpreter_frame_expression_stack_at(tos_idx);
 270     assert(vt_oop != NULL && vt_oop->is_oop() && vt_oop->is_value(),"argument must be a value type");
 271     assert(field_vk == vt_oop->klass(), "Must match");
 272     field_vk->value_store(((char*)(oopDesc*)vt_oop + field_vk->first_field_offset()),
 273             ((char*)(oopDesc*)new_value_h()) + fd.offset(), true, false);
 274   } else {
 275     intptr_t* addr = f.interpreter_frame_expression_stack_at(tos_idx);
 276     copy_primitive_argument(addr, new_value_h, fd.offset(), field_type);
 277   }
 278 
 279   // returning result
 280   thread->set_vm_result(new_value_h());
 281   return (type2size[field_type] + type2size[T_VALUETYPE]) * AbstractInterpreter::stackElementSize;
 282 IRT_END
 283 
 284 IRT_ENTRY(void, InterpreterRuntime::vbox(JavaThread* thread, ConstantPool* pool, int index, oopDesc* value))
 285   assert(EnableMVT, "vbox is supported only when the MVT programming model is enabled");
 286   if (value == NULL) {
 287     THROW(vmSymbols::java_lang_NullPointerException());
 288   }
 289 
 290   // Since the verifier is probably disabled, a few extra type check
 291   Klass* target_klass = pool->klass_at(index, CHECK);
 292   if (target_klass->is_value()) {
 293     THROW_MSG(vmSymbols::java_lang_ClassCastException(), "vbox target is value type");
 294   }
 295   Klass* klass = value->klass();
 296   if (!klass->is_value()) {
 297     THROW_MSG(vmSymbols::java_lang_ClassCastException(), "vbox not from value type");
 298   }
 299   ValueKlass* vtklass = ValueKlass::cast(klass);
 300   if (vtklass->get_vcc_klass() != target_klass) {
 301     THROW_MSG(vmSymbols::java_lang_ClassCastException(), "vbox target is not derive value type box");
 302   }
 303 
 304   oop boxed = vtklass->derive_value_type_copy(Handle(THREAD, value),
 305                                               InstanceKlass::cast(target_klass),
 306                                               CHECK);
 307   thread->set_vm_result(boxed);
 308 IRT_END
 309 
 310 IRT_ENTRY(void, InterpreterRuntime::vunbox(JavaThread* thread, ConstantPool* pool, int index, oopDesc* obj))
 311 assert(EnableMVT, "vunbox is supported only when the MVT programming model is enabled");
 312   if (obj == NULL) {
 313     THROW(vmSymbols::java_lang_NullPointerException());
 314   }
 315   Klass* target_klass = pool->klass_at(index, CHECK);
 316   if (!target_klass->is_value()) {
 317     THROW_MSG(vmSymbols::java_lang_ClassCastException(), "vunbox target is not value type");
 318   }
 319   Klass* klass = obj->klass();
 320   if ((!klass->is_instance_klass()) || klass->is_value()) {
 321     THROW_MSG(vmSymbols::java_lang_ClassCastException(), "vunbox source is not an instance");
 322   }
 323     if (klass != InstanceKlass::cast(target_klass)->get_vcc_klass()) {
 324     THROW_MSG(vmSymbols::java_lang_ClassCastException(), "vunbox target is not derive value type");
 325   }
 326   oop value = ValueKlass::cast(target_klass)->derive_value_type_copy(Handle(THREAD, obj),
 327                                                                  InstanceKlass::cast(target_klass),
 328                                                                  CHECK);
 329   thread->set_vm_result(value);
 330 IRT_END
 331 
 332 IRT_ENTRY(void, InterpreterRuntime::qgetfield(JavaThread* thread, oopDesc* value, int offset))
 333   Handle value_h(THREAD, value);
 334   InstanceKlass* klass = InstanceKlass::cast(value->klass());
 335 
 336   fieldDescriptor fd;
 337   klass->find_field_from_offset(offset, false, &fd);
 338   Klass* field_k = klass->get_value_field_klass(fd.index());
 339   ValueKlass* field_vklass = ValueKlass::cast(field_k);


 340   // allocate instance
 341   instanceOop res = field_vklass->allocate_instance(CHECK);


 342   // copy value
 343   int size = field_vklass->layout_helper_size_in_bytes(field_vklass->layout_helper());
 344   field_vklass->value_store(((char*)(oopDesc*)value_h()) + offset,
 345     ((char*)(oopDesc*)res) + field_vklass->first_field_offset(),true, false);
 346   thread->set_vm_result(res);

















 347 IRT_END
 348 
 349 IRT_ENTRY(void, InterpreterRuntime::qputfield(JavaThread* thread, oopDesc* obj, oopDesc* value, int offset))
 350   Handle value_h(THREAD, value);
 351   Handle obj_h(THREAD, obj);


 352 
 353   InstanceKlass* klass_h = InstanceKlass::cast(obj->klass());



 354   ValueKlass* field_vklass = ValueKlass::cast(value->klass());
 355 
 356   // copy value
 357   int size = field_vklass->layout_helper_size_in_bytes(field_vklass->layout_helper());
 358   field_vklass->value_store(((char*)(oopDesc*)value_h()) + field_vklass->first_field_offset(),
 359                             ((char*)(oopDesc*)obj_h()) + offset, true, false);
 360 IRT_END
 361 






































 362 IRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* thread, BasicType type, jint size))
 363   oop obj = oopFactory::new_typeArray(type, size, CHECK);
 364   thread->set_vm_result(obj);
 365 IRT_END
 366 
 367 
 368 IRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* thread, ConstantPool* pool, int index, jint size))
 369   Klass*    klass = pool->klass_at(index, CHECK);
 370   if (klass->is_value()) { // Logically creates elements, ensure klass init
 371     klass->initialize(CHECK);
 372   }
 373   arrayOop obj = oopFactory::new_array(klass, size, CHECK);
 374   thread->set_vm_result(obj);
 375 IRT_END
 376 
 377 IRT_ENTRY(void, InterpreterRuntime::value_array_load(JavaThread* thread, arrayOopDesc* array, int index))
 378   Klass* klass = array->klass();
 379   assert(klass->is_valueArray_klass() || klass->is_objArray_klass(), "expected value or object array oop");
 380 
 381   if (klass->is_objArray_klass()) {
 382     thread->set_vm_result(((objArrayOop) array)->obj_at(index));
 383   }
 384   else {
 385     // Early prototype: we don't have valorind support...just allocate aref and copy
 386     ValueArrayKlass* vaklass = ValueArrayKlass::cast(klass);
 387     ValueKlass* vklass = vaklass->element_klass();
 388     arrayHandle ah(THREAD, array);
 389     instanceOop value_holder = vklass->allocate_instance(CHECK);

 390     void* src = ((valueArrayOop)ah())->value_at_addr(index, vaklass->layout_helper());
 391     vklass->value_store(src, vklass->data_for_oop(value_holder),
 392                           vaklass->element_byte_size(), true, true);
 393     thread->set_vm_result(value_holder);
 394   }
 395 IRT_END
 396 
 397 IRT_ENTRY(void, InterpreterRuntime::value_array_store(JavaThread* thread, arrayOopDesc* array, int index, void* val))
 398   Klass* klass = array->klass();
 399   assert(klass->is_valueArray_klass() || klass->is_objArray_klass(), "expected value or object array oop");
 400 
 401   if (ArrayKlass::cast(klass)->element_klass() != ((oop)val)->klass()) {
 402     THROW(vmSymbols::java_lang_ArrayStoreException());
 403   }
 404   if (klass->is_objArray_klass()) {
 405     ((objArrayOop) array)->obj_at_put(index, (oop)val);















 406   }
 407   else {

 408     valueArrayOop varray = (valueArrayOop)array;
 409     ValueArrayKlass* vaklass = ValueArrayKlass::cast(klass);
 410     ValueKlass* vklass = vaklass->element_klass();
 411     const int lh = vaklass->layout_helper();
 412     vklass->value_store(vklass->data_for_oop((oop)val), varray->value_at_addr(index, lh),
 413                         vaklass->element_byte_size(), true, false);
 414   }
 415 IRT_END
 416 
 417 IRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* thread, jint* first_size_address))
 418   // We may want to pass in more arguments - could make this slightly faster
 419   ConstantPool* constants = method(thread)->constants();
 420   int          i = get_index_u2(thread, Bytecodes::_multianewarray);
 421   Klass* klass = constants->klass_at(i, CHECK);
 422   int   nof_dims = number_of_dimensions(thread);
 423   assert(klass->is_klass(), "not a class");
 424   assert(nof_dims >= 1, "multianewarray rank must be nonzero");
 425 
 426   if (klass->is_value()) { // Logically creates elements, ensure klass init
 427     klass->initialize(CHECK);
 428   }
 429 
 430   // We must create an array of jints to pass to multi_allocate.
 431   ResourceMark rm(thread);
 432   const int small_dims = 10;
 433   jint dim_array[small_dims];
 434   jint *dims = &dim_array[0];
 435   if (nof_dims > small_dims) {
 436     dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
 437   }
 438   for (int index = 0; index < nof_dims; index++) {
 439     // offset from first_size_address is addressed as local[index]
 440     int n = Interpreter::local_offset_in_bytes(index)/jintSize;
 441     dims[index] = first_size_address[n];
 442   }
 443   oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
 444   thread->set_vm_result(obj);
 445 IRT_END
 446 




















































 447 
 448 IRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* thread, oopDesc* obj))
 449   assert(obj->is_oop(), "must be a valid oop");
 450   assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
 451   InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
 452 IRT_END
 453 
 454 
 455 // Quicken instance-of and check-cast bytecodes
 456 IRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* thread))
 457   // Force resolving; quicken the bytecode
 458   int which = get_index_u2(thread, Bytecodes::_checkcast);
 459   ConstantPool* cpool = method(thread)->constants();
 460   // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
 461   // program we might have seen an unquick'd bytecode in the interpreter but have another
 462   // thread quicken the bytecode before we get here.
 463   // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
 464   Klass* klass = cpool->klass_at(which, CHECK);
 465   thread->set_vm_result_2(klass);
 466 IRT_END


 957 IRT_ENTRY(void, InterpreterRuntime::set_original_bytecode_at(JavaThread* thread, Method* method, address bcp, Bytecodes::Code new_code))
 958   method->set_orig_bytecode_at(method->bci_from(bcp), new_code);
 959 IRT_END
 960 
 961 IRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* thread, Method* method, address bcp))
 962   JvmtiExport::post_raw_breakpoint(thread, method, bcp);
 963 IRT_END
 964 
 965 void InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode) {
 966   Thread* THREAD = thread;
 967   // extract receiver from the outgoing argument list if necessary
 968   Handle receiver(thread, NULL);
 969   if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface ||
 970       bytecode == Bytecodes::_invokespecial) {
 971     ResourceMark rm(thread);
 972     methodHandle m (thread, method(thread));
 973     Bytecode_invoke call(m, bci(thread));
 974     Symbol* signature = call.signature();
 975     receiver = Handle(thread,
 976                   thread->last_frame().interpreter_callee_receiver(signature));
 977     assert(Universe::heap()->is_in_reserved_or_null(receiver()),

 978            "sanity check");
 979     assert(receiver.is_null() ||
 980            !Universe::heap()->is_in_reserved(receiver->klass()),
 981            "sanity check");
 982   }
 983 
 984   // resolve method
 985   CallInfo info;
 986   constantPoolHandle pool(thread, method(thread)->constants());
 987 
 988   {
 989     JvmtiHideSingleStepping jhss(thread);
 990     LinkResolver::resolve_invoke(info, receiver, pool,
 991                                  get_index_u2_cpcache(thread, bytecode), bytecode,
 992                                  CHECK);
 993     if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
 994       int retry_count = 0;
 995       while (info.resolved_method()->is_old()) {
 996         // It is very unlikely that method is redefined more than 100 times
 997         // in the middle of resolve. If it is looping here more than 100 times




  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/javaClasses.inline.hpp"
  27 #include "classfile/systemDictionary.hpp"
  28 #include "classfile/vmSymbols.hpp"
  29 #include "code/codeCache.hpp"
  30 #include "compiler/compileBroker.hpp"
  31 #include "compiler/disassembler.hpp"
  32 #include "gc/shared/collectedHeap.hpp"
  33 #include "interpreter/interpreter.hpp"
  34 #include "interpreter/interpreterRuntime.hpp"
  35 #include "interpreter/linkResolver.hpp"
  36 #include "interpreter/templateTable.hpp"
  37 #include "logging/log.hpp"
  38 #include "memory/oopFactory.hpp"
  39 #include "memory/resourceArea.hpp"
  40 #include "memory/universe.inline.hpp"
  41 #include "memory/vtBuffer.hpp"
  42 #include "oops/constantPool.hpp"
  43 #include "oops/instanceKlass.hpp"
  44 #include "oops/methodData.hpp"
  45 #include "oops/objArrayKlass.hpp"
  46 #include "oops/objArrayOop.inline.hpp"
  47 #include "oops/oop.inline.hpp"
  48 #include "oops/symbol.hpp"
  49 #include "oops/valueKlass.hpp"
  50 #include "oops/valueArrayKlass.hpp"
  51 #include "oops/valueArrayOop.hpp"
  52 #include "prims/jvmtiExport.hpp"
  53 #include "prims/nativeLookup.hpp"
  54 #include "runtime/atomic.hpp"
  55 #include "runtime/biasedLocking.hpp"
  56 #include "runtime/compilationPolicy.hpp"
  57 #include "runtime/deoptimization.hpp"
  58 #include "runtime/fieldDescriptor.hpp"
  59 #include "runtime/handles.inline.hpp"
  60 #include "runtime/icache.hpp"
  61 #include "runtime/interfaceSupport.hpp"


 177     break;
 178   case T_CHAR:
 179     instance()->char_field_put(offset, (jchar) *((int*)addr));
 180     break;
 181   case T_FLOAT:
 182     instance()->float_field_put(offset, (jfloat)*((float*)addr));
 183     break;
 184   case T_DOUBLE:
 185     instance()->double_field_put(offset, (jdouble)*((double*)addr));
 186     break;
 187   case T_BYTE:
 188     instance()->byte_field_put(offset, (jbyte)*((int*)addr));
 189     break;
 190   case T_SHORT:
 191     instance()->short_field_put(offset, (jshort)*((int*)addr));
 192     break;
 193   case T_INT:
 194     instance()->int_field_put(offset, (jint)*((int*)addr));
 195     break;
 196   case T_LONG:
 197     instance()->long_field_put(offset, (jlong)*((long long*)addr));
 198     break;
 199   case T_OBJECT:
 200   case T_ARRAY:
 201   case T_VALUETYPE:
 202     fatal("Should not be handled with this method");
 203     break;
 204   default:
 205     fatal("Unsupported BasicType");
 206   }
 207 }
 208 
 209 IRT_ENTRY(void, InterpreterRuntime::vdefault(JavaThread* thread, ConstantPool* pool, int index))
 210   // Getting the ValueKlass
 211   Klass* k = pool->klass_at(index, CHECK);
 212   assert(k->is_value(), "vdefault argument must be the value type class");
 213   ValueKlass* vklass = ValueKlass::cast(k);
 214 
 215   vklass->initialize(THREAD);
 216 
 217   // Creating value
 218   bool in_heap;
 219   instanceOop value = vklass->allocate_buffered_or_heap_instance(&in_heap, CHECK);
 220   Handle value_h = Handle(THREAD, value);
 221 





 222   thread->set_vm_result(value_h());
 223 IRT_END
 224 
 225 IRT_ENTRY(int, InterpreterRuntime::vwithfield(JavaThread* thread, ConstantPoolCache* cp_cache))
 226   // Getting the ValueKlass
 227   int index = ConstantPool::decode_cpcache_index(get_index_u2_cpcache(thread, Bytecodes::_vwithfield));
 228   ConstantPoolCacheEntry* cp_entry = cp_cache->entry_at(index);
 229   assert(cp_entry->is_resolved(Bytecodes::_vwithfield), "Should have been resolved");
 230   Klass* klass = cp_entry->f1_as_klass();
 231   assert(klass->is_value(), "vwithfield only applies to value types");
 232   ValueKlass* vklass = ValueKlass::cast(klass);
 233 
 234   // Getting Field information
 235   int offset = cp_entry->f2_as_index();
 236   fieldDescriptor fd;
 237   vklass->find_field_from_offset(offset, false, &fd);
 238   Symbol* field_signature = fd.signature();
 239   ResourceMark rm(THREAD);
 240   const char* signature = (const char *) field_signature->as_utf8();
 241   BasicType field_type = char2type(signature[0]);
 242 
 243   // Getting old value
 244   frame f = last_frame(thread);
 245   jint tos_idx = f.interpreter_frame_expression_stack_size() - 1;
 246   int vt_offset = type2size[field_type];
 247   oop old_value = *(oop*)f.interpreter_frame_expression_stack_at(tos_idx - vt_offset);
 248   assert(old_value != NULL && old_value->is_oop() && old_value->is_value(),"Verifying receiver");
 249   Handle old_value_h(THREAD, old_value);
 250 
 251   // Creating new value by copying the one passed in argument
 252   bool in_heap;
 253   instanceOop new_value = vklass->allocate_buffered_or_heap_instance(&in_heap,
 254       CHECK_((type2size[field_type]) * AbstractInterpreter::stackElementSize));
 255   Handle new_value_h = Handle(THREAD, new_value);
 256   int first_offset = vklass->first_field_offset();
 257   vklass->value_store(vklass->data_for_oop(old_value_h()),
 258       vklass->data_for_oop(new_value_h()), in_heap, false);
 259 
 260   // Updating the field specified in arguments
 261   if (field_type == T_OBJECT || field_type == T_ARRAY) {
 262     oop aoop = *(oop*)f.interpreter_frame_expression_stack_at(tos_idx);
 263     assert(aoop == NULL || (aoop->is_oop() && (!aoop->is_value())),"argument must be a reference type");
 264     new_value_h()->obj_field_put(fd.offset(), aoop);
 265   } else if (field_type == T_VALUETYPE) {
 266     Klass* field_k = vklass->get_value_field_klass(fd.index());
 267     ValueKlass* field_vk = ValueKlass::cast(field_k);
 268     oop vt_oop = *(oop*)f.interpreter_frame_expression_stack_at(tos_idx);
 269     assert(vt_oop != NULL && vt_oop->is_oop() && vt_oop->is_value(),"argument must be a value type");
 270     assert(field_vk == vt_oop->klass(), "Must match");
 271     field_vk->value_store(field_vk->data_for_oop(vt_oop),
 272         ((char*)(oopDesc*)new_value_h()) + fd.offset(), true, false);
 273   } else {
 274     intptr_t* addr = f.interpreter_frame_expression_stack_at(tos_idx);
 275     copy_primitive_argument(addr, new_value_h, fd.offset(), field_type);
 276   }
 277 
 278   // returning result
 279   thread->set_vm_result(new_value_h());
 280   return (type2size[field_type] + type2size[T_VALUETYPE]) * AbstractInterpreter::stackElementSize;
 281 IRT_END
 282 
 283 IRT_ENTRY(void, InterpreterRuntime::vbox(JavaThread* thread, ConstantPool* pool, int index, oopDesc* value))
 284   assert(EnableMVT, "vbox is supported only when the MVT programming model is enabled");
 285   if (value == NULL) {
 286     THROW(vmSymbols::java_lang_NullPointerException());
 287   }
 288 
 289   // Since the verifier is probably disabled, a few extra type check
 290   Klass* target_klass = pool->klass_at(index, CHECK);
 291   if (target_klass->is_value()) {
 292     THROW_MSG(vmSymbols::java_lang_ClassCastException(), "vbox target is value type");
 293   }
 294   Klass* klass = value->klass();
 295   if (!klass->is_value()) {
 296     THROW_MSG(vmSymbols::java_lang_ClassCastException(), "vbox not from value type");
 297   }
 298   ValueKlass* vtklass = ValueKlass::cast(klass);
 299   if (vtklass->get_vcc_klass() != target_klass) {
 300     THROW_MSG(vmSymbols::java_lang_ClassCastException(), "vbox target is not derive value type box");
 301   }
 302   oop box = vtklass->box(Handle(THREAD, value),

 303                          InstanceKlass::cast(target_klass),
 304                          CHECK);
 305   thread->set_vm_result(box);
 306 IRT_END
 307 
 308 IRT_ENTRY(void, InterpreterRuntime::vunbox(JavaThread* thread, ConstantPool* pool, int index, oopDesc* obj))
 309 assert(EnableMVT, "vunbox is supported only when the MVT programming model is enabled");
 310   if (obj == NULL) {
 311     THROW(vmSymbols::java_lang_NullPointerException());
 312   }
 313   Klass* target_klass = pool->klass_at(index, CHECK);
 314   if (!target_klass->is_value()) {
 315     THROW_MSG(vmSymbols::java_lang_ClassCastException(), "vunbox target is not value type");
 316   }
 317   Klass* klass = obj->klass();
 318   if ((!klass->is_instance_klass()) || klass->is_value()) {
 319     THROW_MSG(vmSymbols::java_lang_ClassCastException(), "vunbox source is not an instance");
 320   }
 321     if (klass != InstanceKlass::cast(target_klass)->get_vcc_klass()) {
 322     THROW_MSG(vmSymbols::java_lang_ClassCastException(), "vunbox target is not derive value type");
 323   }
 324   oop value = ValueKlass::cast(target_klass)->unbox(Handle(THREAD, obj),
 325                                                 InstanceKlass::cast(target_klass),
 326                                                 CHECK);
 327   thread->set_vm_result(value);
 328 IRT_END
 329 
 330 IRT_ENTRY(void, InterpreterRuntime::qgetfield(JavaThread* thread, oopDesc* value, int offset))
 331   Handle value_h(THREAD, value);
 332   InstanceKlass* klass = InstanceKlass::cast(value->klass());
 333 
 334   fieldDescriptor fd;
 335   klass->find_field_from_offset(offset, false, &fd);
 336   Klass* field_k = klass->get_value_field_klass(fd.index());
 337   ValueKlass* field_vklass = ValueKlass::cast(field_k);
 338   field_vklass->initialize(THREAD);
 339 
 340   // allocate instance
 341   bool in_heap;
 342   instanceOop res = field_vklass->allocate_buffered_or_heap_instance(&in_heap, CHECK);
 343   instanceHandle res_h(THREAD, res);
 344   // copy value

 345   field_vklass->value_store(((char*)(oopDesc*)value_h()) + offset,
 346                             field_vklass->data_for_oop(res), in_heap, false);
 347   thread->set_vm_result(res_h());
 348 IRT_END
 349 
 350 IRT_ENTRY(void, InterpreterRuntime::initialize_static_value_field(JavaThread* thread, oopDesc* mirror, int offset))
 351   instanceHandle mirror_h(THREAD, (instanceOop)mirror);
 352   InstanceKlass* klass = InstanceKlass::cast(java_lang_Class::as_Klass(mirror));
 353   assert(mirror->obj_field(offset) == NULL,"Field must not be initialized twice");
 354 
 355   fieldDescriptor fd;
 356   klass->find_field_from_offset(offset, true, &fd);
 357   Klass* field_k = klass->get_value_field_klass(fd.index());
 358   ValueKlass* field_vklass = ValueKlass::cast(field_k);
 359   // allocate instance, because it is going to be assigned to a static field
 360   // it must not be a buffered value
 361   instanceOop res = field_vklass->allocate_instance(CHECK);
 362   instanceHandle res_h(THREAD, res);
 363   mirror_h()->obj_field_put(offset, res_h());
 364   thread->set_vm_result(res_h());
 365 IRT_END
 366 
 367 IRT_ENTRY(void, InterpreterRuntime::qputfield(JavaThread* thread, oopDesc* obj, oopDesc* value, int offset))
 368   Handle value_h(THREAD, value);
 369   Handle obj_h(THREAD, obj);
 370   assert(!obj_h()->klass()->is_value(), "obj must be an object");
 371   assert(value_h()->klass()->is_value(), "value must be an value type");
 372 
 373   InstanceKlass* klass = InstanceKlass::cast(obj->klass());
 374   fieldDescriptor fd;
 375   klass->find_field_from_offset(offset, false, &fd);
 376   Klass* field_k = klass->get_value_field_klass(fd.index());
 377   ValueKlass* field_vklass = ValueKlass::cast(value->klass());
 378   assert(field_k == field_vklass, "Field descriptor and argument must match");
 379   // copy value
 380   field_vklass->value_store(field_vklass->data_for_oop(value_h()),

 381                             ((char*)(oopDesc*)obj_h()) + offset, true, false);
 382 IRT_END
 383 
 384 IRT_ENTRY(void, InterpreterRuntime::qputstatic(JavaThread* thread, oopDesc* value))
 385   instanceHandle value_h(THREAD, (instanceOop)value);
 386   assert(value_h()->is_value(), "qputstatic only deals with value arguments");
 387   Method* m = last_frame(thread).interpreter_frame_method();
 388   jint bci = last_frame(thread).interpreter_frame_bci();
 389   assert(m->code_at(bci) == Bytecodes::_putstatic, "qputstatic is a particular case of putstatic");
 390   ConstantPoolCache* cp_cache = last_frame(thread).interpreter_frame_method()->constants()->cache();
 391   int index = ConstantPool::decode_cpcache_index(get_index_u2_cpcache(thread, Bytecodes::_putstatic));
 392   ConstantPoolCacheEntry* cp_entry = cp_cache->entry_at(index);
 393   assert(cp_entry->is_field_entry(), "Sanity check");
 394 
 395   InstanceKlass* klass = InstanceKlass::cast(cp_entry->f1_as_klass());
 396   int offset = cp_entry->f2_as_index();
 397   oop mirror = klass->java_mirror();
 398 
 399   if (Universe::heap()->is_in_reserved(value_h())) {
 400     mirror->obj_field_put(offset, value_h());
 401   } else {
 402     // The argument is a buffered value, a copy must be created in the Java heap
 403     // because a static field cannot point to a thread-local buffered value
 404     fieldDescriptor fd;
 405     klass->find_field_from_offset(offset, false, &fd);
 406     Klass* field_k = klass->get_value_field_klass(fd.index());
 407     ValueKlass* field_vklass = ValueKlass::cast(field_k);
 408     assert(field_vklass == value->klass(), "Field descriptor and argument must match");
 409     // allocate heap instance
 410     instanceOop res = field_vklass->allocate_instance(CHECK);
 411     assert(Universe::heap()->is_in_reserved(res), "Must be in the Java heap");
 412     instanceHandle res_h(THREAD, res);
 413     // copy value
 414     field_vklass->value_store(field_vklass->data_for_oop(value_h()),
 415                               field_vklass->data_for_oop(res), true, false);
 416     // writing static field
 417     mirror->obj_field_put(offset, res_h());
 418     assert(mirror->obj_field(offset) != NULL,"Sanity check");
 419   }
 420 IRT_END
 421 
 422 IRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* thread, BasicType type, jint size))
 423   oop obj = oopFactory::new_typeArray(type, size, CHECK);
 424   thread->set_vm_result(obj);
 425 IRT_END
 426 
 427 
 428 IRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* thread, ConstantPool* pool, int index, jint size))
 429   Klass*    klass = pool->klass_at(index, CHECK);
 430   if (klass->is_value()) { // Logically creates elements, ensure klass init
 431     klass->initialize(CHECK);
 432   }
 433   arrayOop obj = oopFactory::new_array(klass, size, CHECK);
 434   thread->set_vm_result(obj);
 435 IRT_END
 436 
 437 IRT_ENTRY(void, InterpreterRuntime::value_array_load(JavaThread* thread, arrayOopDesc* array, int index))
 438   Klass* klass = array->klass();
 439   assert(klass->is_valueArray_klass() || klass->is_objArray_klass(), "expected value or object array oop");
 440 
 441   if (klass->is_objArray_klass()) {
 442     thread->set_vm_result(((objArrayOop) array)->obj_at(index));
 443   }
 444   else {

 445     ValueArrayKlass* vaklass = ValueArrayKlass::cast(klass);
 446     ValueKlass* vklass = vaklass->element_klass();
 447     arrayHandle ah(THREAD, array);
 448     bool in_heap;
 449     instanceOop value_holder = vklass->allocate_buffered_or_heap_instance(&in_heap, CHECK);
 450     void* src = ((valueArrayOop)ah())->value_at_addr(index, vaklass->layout_helper());
 451     vklass->value_store(src, vklass->data_for_oop(value_holder),
 452                           vaklass->element_byte_size(), in_heap, false);
 453     thread->set_vm_result(value_holder);
 454   }
 455 IRT_END
 456 
 457 IRT_ENTRY(void, InterpreterRuntime::value_array_store(JavaThread* thread, arrayOopDesc* array, int index, void* val))
 458   Klass* klass = array->klass();
 459   assert(klass->is_valueArray_klass() || klass->is_objArray_klass(), "expected value or object array oop");
 460 
 461   if (ArrayKlass::cast(klass)->element_klass() != ((oop)val)->klass()) {
 462     THROW(vmSymbols::java_lang_ArrayStoreException());
 463   }
 464   if (klass->is_objArray_klass()) {
 465     if(!Universe::heap()->is_in_reserved(val)) {
 466       // A Java heap allocated copy must be made because an array cannot
 467       // reference a thread-local buffered value
 468       Handle val_h(THREAD, (oop)val);
 469       ObjArrayKlass* aklass = ObjArrayKlass::cast(klass);
 470       Klass* eklass = aklass->element_klass();
 471       assert(eklass->is_value(), "Sanity check");
 472       assert(eklass == ((oop)val)->klass(), "Sanity check");
 473       ValueKlass* vklass = ValueKlass::cast(eklass);
 474       // allocate heap instance
 475       instanceOop res = vklass->allocate_instance(CHECK);
 476       Handle res_h(THREAD, res);
 477       // copy value
 478       vklass->value_store(((char*)(oopDesc*)val_h()) + vklass->first_field_offset(),
 479                             ((char*)(oopDesc*)res_h()) + vklass->first_field_offset(),true, false);
 480       val = res_h();
 481     }
 482     ((objArrayOop) array)->obj_at_put(index, (oop)val);
 483   } else {
 484     valueArrayOop varray = (valueArrayOop)array;
 485     ValueArrayKlass* vaklass = ValueArrayKlass::cast(klass);
 486     ValueKlass* vklass = vaklass->element_klass();
 487     const int lh = vaklass->layout_helper();
 488     vklass->value_store(vklass->data_for_oop((oop)val), varray->value_at_addr(index, lh),
 489                         vaklass->element_byte_size(), true, false);
 490   }
 491 IRT_END
 492 
 493 IRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* thread, jint* first_size_address))
 494   // We may want to pass in more arguments - could make this slightly faster
 495   ConstantPool* constants = method(thread)->constants();
 496   int          i = get_index_u2(thread, Bytecodes::_multianewarray);
 497   Klass* klass = constants->klass_at(i, CHECK);
 498   int   nof_dims = number_of_dimensions(thread);
 499   assert(klass->is_klass(), "not a class");
 500   assert(nof_dims >= 1, "multianewarray rank must be nonzero");
 501 
 502   if (klass->is_value()) { // Logically creates elements, ensure klass init
 503     klass->initialize(CHECK);
 504   }
 505 
 506   // We must create an array of jints to pass to multi_allocate.
 507   ResourceMark rm(thread);
 508   const int small_dims = 10;
 509   jint dim_array[small_dims];
 510   jint *dims = &dim_array[0];
 511   if (nof_dims > small_dims) {
 512     dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
 513   }
 514   for (int index = 0; index < nof_dims; index++) {
 515     // offset from first_size_address is addressed as local[index]
 516     int n = Interpreter::local_offset_in_bytes(index)/jintSize;
 517     dims[index] = first_size_address[n];
 518   }
 519   oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
 520   thread->set_vm_result(obj);
 521 IRT_END
 522 
 523 IRT_ENTRY(void, InterpreterRuntime::recycle_vtbuffer(JavaThread* thread))
 524   VTBuffer::recycle_vtbuffer(thread, last_frame(thread));
 525 IRT_END
 526 
 527 IRT_ENTRY(void, InterpreterRuntime::recycle_buffered_values(JavaThread* thread))
 528   frame f = thread->last_frame();
 529   assert(f.is_interpreted_frame(), "recycling can only be triggered from interpreted frames");
 530   VTBuffer::recycle_vt_in_frame(thread, &f);
 531 IRT_END
 532 
 533 IRT_ENTRY(void, InterpreterRuntime::fix_frame_vt_alloc_ptr(JavaThread* thread))
 534   frame f = thread->last_frame();
 535   VTBuffer::fix_frame_vt_alloc_ptr(f, VTBufferChunk::chunk(thread->vt_alloc_ptr()));
 536 IRT_END
 537 
 538 IRT_ENTRY(void, InterpreterRuntime::return_value(JavaThread* thread, oopDesc* obj))
 539   if (Universe::heap()->is_in_reserved(obj)) {
 540     thread->set_vm_result(obj);
 541     return;
 542   }
 543   assert(obj->klass()->is_value(), "Sanity check");
 544   ValueKlass* vk = ValueKlass::cast(obj->klass());
 545   RegisterMap reg_map(thread, false);
 546   frame current_frame = last_frame(thread);
 547   frame caller_frame = current_frame.sender(&reg_map);
 548   if (!caller_frame.is_interpreted_frame()) {
 549     // caller is not an interpreted frame, creating a new value in Java heap
 550     Handle obj_h(THREAD, obj);
 551     instanceOop res = vk->allocate_instance(CHECK);
 552     Handle res_h(THREAD, res);
 553     // copy value
 554     vk->value_store(vk->data_for_oop(obj_h()),
 555                     vk->data_for_oop(res_h()), true, false);
 556     thread->set_vm_result(res_h());
 557     return;
 558   } else {
 559     oop dest = VTBuffer::relocate_return_value(thread, current_frame, obj);
 560     thread->set_vm_result(dest);
 561   }
 562 IRT_END
 563 
 564 IRT_ENTRY(void, InterpreterRuntime::check_areturn(JavaThread* thread, oopDesc* obj))
 565   if (obj != NULL) {
 566     Klass* k = obj->klass();
 567     if (k->is_value()) {
 568       ResourceMark rm(thread);
 569       tty->print_cr("areturn used on a value from %s", k->name()->as_C_string());
 570     }
 571     assert(!k->is_value(), "areturn should never be used on values");
 572   }
 573   thread->set_vm_result(obj);
 574 IRT_END
 575 
 576 IRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* thread, oopDesc* obj))
 577   assert(obj->is_oop(), "must be a valid oop");
 578   assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
 579   InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
 580 IRT_END
 581 
 582 
 583 // Quicken instance-of and check-cast bytecodes
 584 IRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* thread))
 585   // Force resolving; quicken the bytecode
 586   int which = get_index_u2(thread, Bytecodes::_checkcast);
 587   ConstantPool* cpool = method(thread)->constants();
 588   // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
 589   // program we might have seen an unquick'd bytecode in the interpreter but have another
 590   // thread quicken the bytecode before we get here.
 591   // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
 592   Klass* klass = cpool->klass_at(which, CHECK);
 593   thread->set_vm_result_2(klass);
 594 IRT_END


1085 IRT_ENTRY(void, InterpreterRuntime::set_original_bytecode_at(JavaThread* thread, Method* method, address bcp, Bytecodes::Code new_code))
1086   method->set_orig_bytecode_at(method->bci_from(bcp), new_code);
1087 IRT_END
1088 
1089 IRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* thread, Method* method, address bcp))
1090   JvmtiExport::post_raw_breakpoint(thread, method, bcp);
1091 IRT_END
1092 
1093 void InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode) {
1094   Thread* THREAD = thread;
1095   // extract receiver from the outgoing argument list if necessary
1096   Handle receiver(thread, NULL);
1097   if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface ||
1098       bytecode == Bytecodes::_invokespecial) {
1099     ResourceMark rm(thread);
1100     methodHandle m (thread, method(thread));
1101     Bytecode_invoke call(m, bci(thread));
1102     Symbol* signature = call.signature();
1103     receiver = Handle(thread,
1104                   thread->last_frame().interpreter_callee_receiver(signature));
1105     assert(Universe::heap()->is_in_reserved_or_null(receiver())
1106            || VTBuffer::is_in_vt_buffer(receiver()),
1107            "sanity check");
1108     assert(receiver.is_null() ||
1109            !Universe::heap()->is_in_reserved(receiver->klass()),
1110            "sanity check");
1111   }
1112 
1113   // resolve method
1114   CallInfo info;
1115   constantPoolHandle pool(thread, method(thread)->constants());
1116 
1117   {
1118     JvmtiHideSingleStepping jhss(thread);
1119     LinkResolver::resolve_invoke(info, receiver, pool,
1120                                  get_index_u2_cpcache(thread, bytecode), bytecode,
1121                                  CHECK);
1122     if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
1123       int retry_count = 0;
1124       while (info.resolved_method()->is_old()) {
1125         // It is very unlikely that method is redefined more than 100 times
1126         // in the middle of resolve. If it is looping here more than 100 times


< prev index next >