< prev index next >

src/hotspot/share/interpreter/interpreterRuntime.cpp

Print this page

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

















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

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

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

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

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

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

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

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

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

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











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