< prev index next >

src/hotspot/share/interpreter/interpreterRuntime.cpp

Print this page

 102   int get_index_u2(Bytecodes::Code bc) const     { return bytecode().get_index_u2(bc); }
 103   int get_index_u4(Bytecodes::Code bc) const     { return bytecode().get_index_u4(bc); }
 104   int number_of_dimensions() const               { return bcp()[3]; }
 105 
 106   oop callee_receiver(Symbol* signature) {
 107     return _last_frame.interpreter_callee_receiver(signature);
 108   }
 109   BasicObjectLock* monitor_begin() const {
 110     return _last_frame.interpreter_frame_monitor_begin();
 111   }
 112   BasicObjectLock* monitor_end() const {
 113     return _last_frame.interpreter_frame_monitor_end();
 114   }
 115   BasicObjectLock* next_monitor(BasicObjectLock* current) const {
 116     return _last_frame.next_monitor_in_interpreter_frame(current);
 117   }
 118 
 119   frame& get_frame()                             { return _last_frame; }
 120 };
 121 

















 122 //------------------------------------------------------------------------------------------------------------------------
 123 // State accessors
 124 
 125 void InterpreterRuntime::set_bcp_and_mdp(address bcp, JavaThread* current) {
 126   LastFrameAccessor last_frame(current);
 127   last_frame.set_bcp(bcp);
 128   if (ProfileInterpreter) {
 129     // ProfileTraps uses MDOs independently of ProfileInterpreter.
 130     // That is why we must check both ProfileInterpreter and mdo != nullptr.
 131     MethodData* mdo = last_frame.method()->method_data();
 132     if (mdo != nullptr) {
 133       NEEDS_CLEANUP;
 134       last_frame.set_mdp(mdo->bci_to_dp(last_frame.bci()));
 135     }
 136   }
 137 }
 138 
 139 //------------------------------------------------------------------------------------------------------------------------
 140 // Constants
 141 

 200     int offset = java_lang_boxing_object::value_offset(type);
 201     intptr_t flags = ((as_TosState(type) << ConstantPoolCache::tos_state_shift)
 202                       | (offset & ConstantPoolCache::field_index_mask));
 203     current->set_vm_result_metadata((Metadata*)flags);
 204   }
 205 }
 206 JRT_END
 207 
 208 
 209 //------------------------------------------------------------------------------------------------------------------------
 210 // Allocation
 211 
 212 JRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* current, ConstantPool* pool, int index))
 213   Klass* k = pool->klass_at(index, CHECK);
 214   InstanceKlass* klass = InstanceKlass::cast(k);
 215 
 216   // Make sure we are not instantiating an abstract klass
 217   klass->check_valid_for_instantiation(true, CHECK);
 218 
 219   // Make sure klass is initialized
 220   klass->initialize(CHECK);
 221 
 222   oop obj = klass->allocate_instance(CHECK);
 223   current->set_vm_result_oop(obj);
 224 JRT_END
 225 
 226 
 227 JRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* current, BasicType type, jint size))
 228   oop obj = oopFactory::new_typeArray(type, size, CHECK);
 229   current->set_vm_result_oop(obj);
 230 JRT_END
 231 
 232 
 233 JRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* current, ConstantPool* pool, int index, jint size))
 234   Klass*    klass = pool->klass_at(index, CHECK);
 235   objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
 236   current->set_vm_result_oop(obj);
 237 JRT_END
 238 
 239 
 240 JRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* current, jint* first_size_address))

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

 644   LastFrameAccessor last_frame(current);
 645   constantPoolHandle pool(current, last_frame.method()->constants());
 646   methodHandle m(current, last_frame.method());
 647 
 648   resolve_get_put(bytecode, last_frame.get_index_u2(bytecode), m, pool, true /*initialize_holder*/, current);
 649 }
 650 
 651 void InterpreterRuntime::resolve_get_put(Bytecodes::Code bytecode, int field_index,
 652                                          methodHandle& m,
 653                                          constantPoolHandle& pool,
 654                                          bool initialize_holder, TRAPS) {
 655   fieldDescriptor info;
 656   bool is_put    = (bytecode == Bytecodes::_putfield  || bytecode == Bytecodes::_nofast_putfield ||
 657                     bytecode == Bytecodes::_putstatic);
 658   bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic);
 659 
 660   {
 661     JvmtiHideSingleStepping jhss(THREAD);
 662     LinkResolver::resolve_field_access(info, pool, field_index,
 663                                        m, bytecode, initialize_holder, CHECK);
 664   } // end JvmtiHideSingleStepping
 665 
 666   // check if link resolution caused cpCache to be updated
 667   if (pool->resolved_field_entry_at(field_index)->is_resolved(bytecode)) return;
 668 
 669   // compute auxiliary field attributes
 670   TosState state  = as_TosState(info.field_type());
 671 
 672   // Resolution of put instructions on final fields is delayed. That is required so that
 673   // exceptions are thrown at the correct place (when the instruction is actually invoked).
 674   // If we do not resolve an instruction in the current pass, leaving the put_code
 675   // set to zero will cause the next put instruction to the same field to reresolve.
 676 
 677   // Resolution of put instructions to final instance fields with invalid updates (i.e.,
 678   // to final instance fields with updates originating from a method different than <init>)
 679   // is inhibited. A putfield instruction targeting an instance final field must throw
 680   // an IllegalAccessError if the instruction is not in an instance
 681   // initializer method <init>. If resolution were not inhibited, a putfield
 682   // in an initializer method could be resolved in the initializer. Subsequent
 683   // putfield instructions to the same field would then use cached information.

 797     ResourceMark rm(current);
 798     methodHandle m (current, last_frame.method());
 799     Bytecode_invoke call(m, last_frame.bci());
 800     Symbol* signature = call.signature();
 801     receiver = Handle(current, last_frame.callee_receiver(signature));
 802 
 803     assert(Universe::heap()->is_in_or_null(receiver()),
 804            "sanity check");
 805     assert(receiver.is_null() ||
 806            !Universe::heap()->is_in(receiver->klass()),
 807            "sanity check");
 808   }
 809 
 810   // resolve method
 811   CallInfo info;
 812   constantPoolHandle pool(current, last_frame.method()->constants());
 813 
 814   methodHandle resolved_method;
 815 
 816   int method_index = last_frame.get_index_u2(bytecode);
 817   {
 818     JvmtiHideSingleStepping jhss(current);
 819     JavaThread* THREAD = current; // For exception macros.
 820     LinkResolver::resolve_invoke(info, receiver, pool,
 821                                  method_index, bytecode,
 822                                  THREAD);
 823 
 824     if (HAS_PENDING_EXCEPTION) {
 825       if (ProfileTraps && PENDING_EXCEPTION->klass()->name() == vmSymbols::java_lang_NullPointerException()) {
 826         // Preserve the original exception across the call to note_trap()
 827         PreserveExceptionMark pm(current);
 828         // Recording the trap will help the compiler to potentially recognize this exception as "hot"
 829         note_trap(current, Deoptimization::Reason_null_check);
 830       }
 831       return;
 832     }
 833 
 834     resolved_method = methodHandle(current, info.resolved_method());

 835   } // end JvmtiHideSingleStepping
 836 
 837   update_invoke_cp_cache_entry(info, bytecode, resolved_method, pool, method_index);
 838 }
 839 
 840 void InterpreterRuntime::update_invoke_cp_cache_entry(CallInfo& info, Bytecodes::Code bytecode,
 841                                                       methodHandle& resolved_method,
 842                                                       constantPoolHandle& pool,
 843                                                       int method_index) {
 844   // Don't allow safepoints until the method is cached.
 845   NoSafepointVerifier nsv;
 846 
 847   // check if link resolution caused cpCache to be updated
 848   ConstantPoolCache* cache = pool->cache();
 849   if (cache->resolved_method_entry_at(method_index)->is_resolved(bytecode)) return;
 850 
 851 #ifdef ASSERT
 852   if (bytecode == Bytecodes::_invokeinterface) {
 853     if (resolved_method->method_holder() == vmClasses::Object_klass()) {
 854       // NOTE: THIS IS A FIX FOR A CORNER CASE in the JVM spec

 102   int get_index_u2(Bytecodes::Code bc) const     { return bytecode().get_index_u2(bc); }
 103   int get_index_u4(Bytecodes::Code bc) const     { return bytecode().get_index_u4(bc); }
 104   int number_of_dimensions() const               { return bcp()[3]; }
 105 
 106   oop callee_receiver(Symbol* signature) {
 107     return _last_frame.interpreter_callee_receiver(signature);
 108   }
 109   BasicObjectLock* monitor_begin() const {
 110     return _last_frame.interpreter_frame_monitor_begin();
 111   }
 112   BasicObjectLock* monitor_end() const {
 113     return _last_frame.interpreter_frame_monitor_end();
 114   }
 115   BasicObjectLock* next_monitor(BasicObjectLock* current) const {
 116     return _last_frame.next_monitor_in_interpreter_frame(current);
 117   }
 118 
 119   frame& get_frame()                             { return _last_frame; }
 120 };
 121 
 122 class ProfileTrapsMark : public StackObj {
 123   JavaThread* _thread;
 124  public:
 125   ProfileTrapsMark(JavaThread* current) : _thread(current) {}
 126   ~ProfileTrapsMark() {
 127     JavaThread* THREAD = _thread;
 128     if (HAS_PENDING_EXCEPTION) {
 129       if (ProfileTraps && PENDING_EXCEPTION->klass()->name() == vmSymbols::java_lang_NullPointerException()) {
 130         // Preserve the original exception across the call to note_trap()
 131         PreserveExceptionMark pm(_thread);
 132         // Recording the trap will help the compiler to potentially recognize this exception as "hot"
 133         InterpreterRuntime::note_trap(_thread, Deoptimization::Reason_null_check);
 134       }
 135     }
 136   }
 137 };
 138 
 139 //------------------------------------------------------------------------------------------------------------------------
 140 // State accessors
 141 
 142 void InterpreterRuntime::set_bcp_and_mdp(address bcp, JavaThread* current) {
 143   LastFrameAccessor last_frame(current);
 144   last_frame.set_bcp(bcp);
 145   if (ProfileInterpreter) {
 146     // ProfileTraps uses MDOs independently of ProfileInterpreter.
 147     // That is why we must check both ProfileInterpreter and mdo != nullptr.
 148     MethodData* mdo = last_frame.method()->method_data();
 149     if (mdo != nullptr) {
 150       NEEDS_CLEANUP;
 151       last_frame.set_mdp(mdo->bci_to_dp(last_frame.bci()));
 152     }
 153   }
 154 }
 155 
 156 //------------------------------------------------------------------------------------------------------------------------
 157 // Constants
 158 

 217     int offset = java_lang_boxing_object::value_offset(type);
 218     intptr_t flags = ((as_TosState(type) << ConstantPoolCache::tos_state_shift)
 219                       | (offset & ConstantPoolCache::field_index_mask));
 220     current->set_vm_result_metadata((Metadata*)flags);
 221   }
 222 }
 223 JRT_END
 224 
 225 
 226 //------------------------------------------------------------------------------------------------------------------------
 227 // Allocation
 228 
 229 JRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* current, ConstantPool* pool, int index))
 230   Klass* k = pool->klass_at(index, CHECK);
 231   InstanceKlass* klass = InstanceKlass::cast(k);
 232 
 233   // Make sure we are not instantiating an abstract klass
 234   klass->check_valid_for_instantiation(true, CHECK);
 235 
 236   // Make sure klass is initialized
 237   klass->initialize_preemptable(CHECK_AND_CLEAR_PREEMPTED);
 238 
 239   oop obj = klass->allocate_instance(CHECK);
 240   current->set_vm_result_oop(obj);
 241 JRT_END
 242 
 243 
 244 JRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* current, BasicType type, jint size))
 245   oop obj = oopFactory::new_typeArray(type, size, CHECK);
 246   current->set_vm_result_oop(obj);
 247 JRT_END
 248 
 249 
 250 JRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* current, ConstantPool* pool, int index, jint size))
 251   Klass*    klass = pool->klass_at(index, CHECK);
 252   objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
 253   current->set_vm_result_oop(obj);
 254 JRT_END
 255 
 256 
 257 JRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* current, jint* first_size_address))

 641                                                                               Klass* interfaceKlass))
 642   ResourceMark rm(current);
 643   char buf[1000];
 644   buf[0] = '\0';
 645   jio_snprintf(buf, sizeof(buf),
 646                "Class %s does not implement the requested interface %s",
 647                recvKlass ? recvKlass->external_name() : "nullptr",
 648                interfaceKlass ? interfaceKlass->external_name() : "nullptr");
 649   THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
 650 JRT_END
 651 
 652 JRT_ENTRY(void, InterpreterRuntime::throw_NullPointerException(JavaThread* current))
 653   THROW(vmSymbols::java_lang_NullPointerException());
 654 JRT_END
 655 
 656 //------------------------------------------------------------------------------------------------------------------------
 657 // Fields
 658 //
 659 
 660 void InterpreterRuntime::resolve_get_put(JavaThread* current, Bytecodes::Code bytecode) {
 661   JavaThread* THREAD = current;
 662   LastFrameAccessor last_frame(current);
 663   constantPoolHandle pool(current, last_frame.method()->constants());
 664   methodHandle m(current, last_frame.method());
 665 
 666   resolve_get_put(bytecode, last_frame.get_index_u2(bytecode), m, pool, StaticMode::initialize_klass_preemptable, CHECK_AND_CLEAR_PREEMPTED);
 667 }
 668 
 669 void InterpreterRuntime::resolve_get_put(Bytecodes::Code bytecode, int field_index,
 670                                          methodHandle& m,
 671                                          constantPoolHandle& pool,
 672                                          StaticMode static_mode, TRAPS) {
 673   fieldDescriptor info;
 674   bool is_put    = (bytecode == Bytecodes::_putfield  || bytecode == Bytecodes::_nofast_putfield ||
 675                     bytecode == Bytecodes::_putstatic);
 676   bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic);
 677 
 678   {
 679     JvmtiHideSingleStepping jhss(THREAD);
 680     LinkResolver::resolve_field_access(info, pool, field_index,
 681                                        m, bytecode, static_mode, CHECK);
 682   } // end JvmtiHideSingleStepping
 683 
 684   // check if link resolution caused cpCache to be updated
 685   if (pool->resolved_field_entry_at(field_index)->is_resolved(bytecode)) return;
 686 
 687   // compute auxiliary field attributes
 688   TosState state  = as_TosState(info.field_type());
 689 
 690   // Resolution of put instructions on final fields is delayed. That is required so that
 691   // exceptions are thrown at the correct place (when the instruction is actually invoked).
 692   // If we do not resolve an instruction in the current pass, leaving the put_code
 693   // set to zero will cause the next put instruction to the same field to reresolve.
 694 
 695   // Resolution of put instructions to final instance fields with invalid updates (i.e.,
 696   // to final instance fields with updates originating from a method different than <init>)
 697   // is inhibited. A putfield instruction targeting an instance final field must throw
 698   // an IllegalAccessError if the instruction is not in an instance
 699   // initializer method <init>. If resolution were not inhibited, a putfield
 700   // in an initializer method could be resolved in the initializer. Subsequent
 701   // putfield instructions to the same field would then use cached information.

 815     ResourceMark rm(current);
 816     methodHandle m (current, last_frame.method());
 817     Bytecode_invoke call(m, last_frame.bci());
 818     Symbol* signature = call.signature();
 819     receiver = Handle(current, last_frame.callee_receiver(signature));
 820 
 821     assert(Universe::heap()->is_in_or_null(receiver()),
 822            "sanity check");
 823     assert(receiver.is_null() ||
 824            !Universe::heap()->is_in(receiver->klass()),
 825            "sanity check");
 826   }
 827 
 828   // resolve method
 829   CallInfo info;
 830   constantPoolHandle pool(current, last_frame.method()->constants());
 831 
 832   methodHandle resolved_method;
 833 
 834   int method_index = last_frame.get_index_u2(bytecode);
 835   { ProfileTrapsMark pt(current);
 836     JvmtiHideSingleStepping jhss(current);
 837     JavaThread* THREAD = current; // For exception macros.
 838     LinkResolver::resolve_invoke(info, receiver, pool,
 839                                  method_index, bytecode,
 840                                  StaticMode::initialize_klass_preemptable, CHECK_AND_CLEAR_PREEMPTED);











 841     resolved_method = methodHandle(current, info.resolved_method());
 842     ResourceMark rm(THREAD);
 843   } // end JvmtiHideSingleStepping
 844 
 845   update_invoke_cp_cache_entry(info, bytecode, resolved_method, pool, method_index);
 846 }
 847 
 848 void InterpreterRuntime::update_invoke_cp_cache_entry(CallInfo& info, Bytecodes::Code bytecode,
 849                                                       methodHandle& resolved_method,
 850                                                       constantPoolHandle& pool,
 851                                                       int method_index) {
 852   // Don't allow safepoints until the method is cached.
 853   NoSafepointVerifier nsv;
 854 
 855   // check if link resolution caused cpCache to be updated
 856   ConstantPoolCache* cache = pool->cache();
 857   if (cache->resolved_method_entry_at(method_index)->is_resolved(bytecode)) return;
 858 
 859 #ifdef ASSERT
 860   if (bytecode == Bytecodes::_invokeinterface) {
 861     if (resolved_method->method_holder() == vmClasses::Object_klass()) {
 862       // NOTE: THIS IS A FIX FOR A CORNER CASE in the JVM spec
< prev index next >