src/hotspot/cpu/arm/interp_masm_arm.hpp
changeset 47216 71c04702a3d5
parent 46427 54713555867e
child 49950 7b916885654d
equal deleted inserted replaced
47215:4ebc2e2fb97c 47216:71c04702a3d5
       
     1 /*
       
     2  * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  *
       
    23  */
       
    24 
       
    25 #ifndef CPU_ARM_VM_INTERP_MASM_ARM_HPP
       
    26 #define CPU_ARM_VM_INTERP_MASM_ARM_HPP
       
    27 
       
    28 #include "asm/macroAssembler.hpp"
       
    29 #include "asm/macroAssembler.inline.hpp"
       
    30 #include "interpreter/invocationCounter.hpp"
       
    31 #include "runtime/frame.hpp"
       
    32 #include "prims/jvmtiExport.hpp"
       
    33 
       
    34 // This file specializes the assember with interpreter-specific macros
       
    35 
       
    36 
       
    37 class InterpreterMacroAssembler: public MacroAssembler {
       
    38 
       
    39  public:
       
    40 
       
    41   // allow JvmtiExport checks to be extended
       
    42   bool can_force_early_return()       { return JvmtiExport::can_force_early_return(); }
       
    43   bool can_post_interpreter_events()  { return JvmtiExport::can_post_interpreter_events(); }
       
    44   bool can_pop_frame()                { return JvmtiExport::can_pop_frame(); }
       
    45   bool can_post_breakpoint()          { return JvmtiExport::can_post_breakpoint(); }
       
    46   bool can_post_field_access()        { return JvmtiExport::can_post_field_access(); }
       
    47   bool can_post_field_modification()  { return JvmtiExport::can_post_field_modification(); }
       
    48   // flags controlled by JVMTI settings
       
    49   bool rewrite_frequent_pairs()       { return RewriteFrequentPairs; }
       
    50 
       
    51  protected:
       
    52 
       
    53   // Template interpreter specific version of call_VM_helper
       
    54   virtual void call_VM_helper(Register oop_result, address entry_point, int number_of_arguments, bool check_exceptions);
       
    55 
       
    56   // base routine for all dispatches
       
    57   typedef enum { DispatchDefault, DispatchNormal } DispatchTableMode;
       
    58   void dispatch_base(TosState state, DispatchTableMode table_mode, bool verifyoop = true);
       
    59 
       
    60  public:
       
    61   InterpreterMacroAssembler(CodeBuffer* code);
       
    62 
       
    63   virtual void check_and_handle_popframe();
       
    64   virtual void check_and_handle_earlyret();
       
    65 
       
    66   // Interpreter-specific registers
       
    67 #if defined(AARCH64) && defined(ASSERT)
       
    68 
       
    69 #define check_stack_top()               _check_stack_top("invalid Rstack_top at " __FILE__ ":" XSTR(__LINE__))
       
    70 #define check_stack_top_on_expansion()  _check_stack_top("invalid Rstack_top at " __FILE__ ":" XSTR(__LINE__), VerifyInterpreterStackTop)
       
    71 #define check_extended_sp(tmp)          _check_extended_sp(tmp, "SP does not match extended SP in frame at " __FILE__ ":" XSTR(__LINE__))
       
    72 #define check_no_cached_stack_top(tmp)  _check_no_cached_stack_top(tmp, "stack_top is already cached in frame at " __FILE__ ":" XSTR(__LINE__))
       
    73 
       
    74   void _check_stack_top(const char* msg, bool enabled = true) {
       
    75       if (enabled) {
       
    76           Label L;
       
    77           cmp(SP, Rstack_top);
       
    78           b(L, ls);
       
    79           stop(msg);
       
    80           bind(L);
       
    81       }
       
    82   }
       
    83 
       
    84   void _check_extended_sp(Register tmp, const char* msg) {
       
    85       Label L;
       
    86       ldr(tmp, Address(FP, frame::interpreter_frame_extended_sp_offset * wordSize));
       
    87       cmp(SP, tmp);
       
    88       b(L, eq);
       
    89       stop(msg);
       
    90       bind(L);
       
    91   }
       
    92 
       
    93   void _check_no_cached_stack_top(Register tmp, const char* msg) {
       
    94       Label L;
       
    95       ldr(tmp, Address(FP, frame::interpreter_frame_stack_top_offset * wordSize));
       
    96       cbz(tmp, L);
       
    97       stop(msg);
       
    98       bind(L);
       
    99   }
       
   100 
       
   101 #else
       
   102 
       
   103   inline void check_stack_top() {}
       
   104   inline void check_stack_top_on_expansion() {}
       
   105   inline void check_extended_sp(Register tmp) {}
       
   106   inline void check_no_cached_stack_top(Register tmp) {}
       
   107 
       
   108 #endif // AARCH64 && ASSERT
       
   109 
       
   110   void save_bcp()                                          { str(Rbcp, Address(FP, frame::interpreter_frame_bcp_offset * wordSize)); }
       
   111   void restore_bcp()                                       { ldr(Rbcp, Address(FP, frame::interpreter_frame_bcp_offset * wordSize)); }
       
   112   void restore_locals()                                    { ldr(Rlocals, Address(FP, frame::interpreter_frame_locals_offset * wordSize)); }
       
   113   void restore_method()                                    { ldr(Rmethod, Address(FP, frame::interpreter_frame_method_offset * wordSize)); }
       
   114   void restore_dispatch();
       
   115 
       
   116 #ifdef AARCH64
       
   117   void save_stack_top()                                    { check_stack_top(); str(Rstack_top, Address(FP, frame::interpreter_frame_stack_top_offset * wordSize)); }
       
   118   void clear_cached_stack_top()                            { str(ZR, Address(FP, frame::interpreter_frame_stack_top_offset * wordSize)); }
       
   119   void restore_stack_top()                                 { ldr(Rstack_top, Address(FP, frame::interpreter_frame_stack_top_offset * wordSize)); clear_cached_stack_top(); check_stack_top(); }
       
   120   void cut_sp_before_call()                                { align_reg(SP, Rstack_top, StackAlignmentInBytes); }
       
   121   void restore_sp_after_call(Register tmp)                 { ldr(tmp, Address(FP, frame::interpreter_frame_extended_sp_offset * wordSize)); mov(SP, tmp); }
       
   122 #endif
       
   123 
       
   124   // Helpers for runtime call arguments/results
       
   125   void get_const(Register reg)                             { ldr(reg, Address(Rmethod, Method::const_offset())); }
       
   126   void get_constant_pool(Register reg)                     { get_const(reg); ldr(reg, Address(reg, ConstMethod::constants_offset())); }
       
   127   void get_constant_pool_cache(Register reg)               { get_constant_pool(reg); ldr(reg, Address(reg, ConstantPool::cache_offset_in_bytes())); }
       
   128   void get_cpool_and_tags(Register cpool, Register tags)   { get_constant_pool(cpool); ldr(tags, Address(cpool, ConstantPool::tags_offset_in_bytes())); }
       
   129 
       
   130   // Sets reg. Blows Rtemp.
       
   131   void get_unsigned_2_byte_index_at_bcp(Register reg, int bcp_offset);
       
   132 
       
   133   // Sets index. Blows reg_tmp.
       
   134   void get_index_at_bcp(Register index, int bcp_offset, Register reg_tmp, size_t index_size = sizeof(u2));
       
   135   // Sets cache, index.
       
   136   void get_cache_and_index_at_bcp(Register cache, Register index, int bcp_offset, size_t index_size = sizeof(u2));
       
   137   void get_cache_and_index_and_bytecode_at_bcp(Register cache, Register index, Register bytecode, int byte_no, int bcp_offset, size_t index_size = sizeof(u2));
       
   138   // Sets cache. Blows reg_tmp.
       
   139   void get_cache_entry_pointer_at_bcp(Register cache, Register reg_tmp, int bcp_offset, size_t index_size = sizeof(u2));
       
   140 
       
   141   // Load object from cpool->resolved_references(*bcp+1)
       
   142   void load_resolved_reference_at_index(Register result, Register tmp);
       
   143 
       
   144   // load cpool->resolved_klass_at(index); Rtemp is corrupted upon return
       
   145   void load_resolved_klass_at_offset(Register Rcpool, Register Rindex, Register Rklass);
       
   146 
       
   147   void store_check_part1(Register card_table_base);                // Sets card_table_base register.
       
   148   void store_check_part2(Register obj, Register card_table_base, Register tmp);
       
   149 
       
   150   void set_card(Register card_table_base, Address card_table_addr, Register tmp);
       
   151 
       
   152   void pop_ptr(Register r);
       
   153   void pop_i(Register r = R0_tos);
       
   154 #ifdef AARCH64
       
   155   void pop_l(Register r = R0_tos);
       
   156 #else
       
   157   void pop_l(Register lo = R0_tos_lo, Register hi = R1_tos_hi);
       
   158 #endif
       
   159   void pop_f(FloatRegister fd);
       
   160   void pop_d(FloatRegister fd);
       
   161 
       
   162   void push_ptr(Register r);
       
   163   void push_i(Register r = R0_tos);
       
   164 #ifdef AARCH64
       
   165   void push_l(Register r = R0_tos);
       
   166 #else
       
   167   void push_l(Register lo = R0_tos_lo, Register hi = R1_tos_hi);
       
   168 #endif
       
   169   void push_f();
       
   170   void push_d();
       
   171 
       
   172   // Transition vtos -> state. Blows R0, R1. Sets TOS cached value.
       
   173   void pop(TosState state);
       
   174   // Transition state -> vtos. Blows Rtemp.
       
   175   void push(TosState state);
       
   176 
       
   177 #ifndef AARCH64
       
   178   // The following methods are overridden to allow overloaded calls to
       
   179   //   MacroAssembler::push/pop(Register)
       
   180   //   MacroAssembler::push/pop(RegisterSet)
       
   181   //   InterpreterMacroAssembler::push/pop(TosState)
       
   182   void push(Register rd, AsmCondition cond = al)         { MacroAssembler::push(rd, cond);      }
       
   183   void pop(Register rd, AsmCondition cond = al)          { MacroAssembler::pop(rd, cond);       }
       
   184 
       
   185   void push(RegisterSet reg_set, AsmCondition cond = al) { MacroAssembler::push(reg_set, cond); }
       
   186   void pop(RegisterSet reg_set, AsmCondition cond = al)  { MacroAssembler::pop(reg_set, cond);  }
       
   187 
       
   188   // Converts return value in R0/R1 (interpreter calling conventions) to TOS cached value.
       
   189   void convert_retval_to_tos(TosState state);
       
   190   // Converts TOS cached value to return value in R0/R1 (according to interpreter calling conventions).
       
   191   void convert_tos_to_retval(TosState state);
       
   192 #endif
       
   193 
       
   194   // JVMTI ForceEarlyReturn support
       
   195   void load_earlyret_value(TosState state);
       
   196 
       
   197   void jump_to_entry(address entry);
       
   198 
       
   199   // Blows Rtemp.
       
   200   void empty_expression_stack() {
       
   201       ldr(Rstack_top, Address(FP, frame::interpreter_frame_monitor_block_top_offset * wordSize));
       
   202       check_stack_top();
       
   203 #ifdef AARCH64
       
   204       clear_cached_stack_top();
       
   205 #else
       
   206       // NULL last_sp until next java call
       
   207       str(zero_register(Rtemp), Address(FP, frame::interpreter_frame_last_sp_offset * wordSize));
       
   208 #endif // AARCH64
       
   209   }
       
   210 
       
   211   // Helpers for swap and dup
       
   212   void load_ptr(int n, Register val);
       
   213   void store_ptr(int n, Register val);
       
   214 
       
   215   // Generate a subtype check: branch to not_subtype if sub_klass is
       
   216   // not a subtype of super_klass.
       
   217   // Profiling code for the subtype check failure (profile_typecheck_failed)
       
   218   // should be explicitly generated by the caller in the not_subtype case.
       
   219   // Blows Rtemp, tmp1, tmp2.
       
   220   void gen_subtype_check(Register Rsub_klass, Register Rsuper_klass,
       
   221                          Label &not_subtype, Register tmp1, Register tmp2);
       
   222 
       
   223   // Dispatching
       
   224   void dispatch_prolog(TosState state, int step = 0);
       
   225   void dispatch_epilog(TosState state, int step = 0);
       
   226   void dispatch_only(TosState state);                      // dispatch by R3_bytecode
       
   227   void dispatch_only_normal(TosState state);               // dispatch normal table by R3_bytecode
       
   228   void dispatch_only_noverify(TosState state);
       
   229   void dispatch_next(TosState state, int step = 0);        // load R3_bytecode from [Rbcp + step] and dispatch by R3_bytecode
       
   230 
       
   231   // jump to an invoked target
       
   232   void prepare_to_jump_from_interpreted();
       
   233   void jump_from_interpreted(Register method);
       
   234 
       
   235   void narrow(Register result);
       
   236 
       
   237   // Returning from interpreted functions
       
   238   //
       
   239   // Removes the current activation (incl. unlocking of monitors)
       
   240   // and sets up the return address.  This code is also used for
       
   241   // exception unwindwing. In that case, we do not want to throw
       
   242   // IllegalMonitorStateExceptions, since that might get us into an
       
   243   // infinite rethrow exception loop.
       
   244   // Additionally this code is used for popFrame and earlyReturn.
       
   245   // In popFrame case we want to skip throwing an exception,
       
   246   // installing an exception, and notifying jvmdi.
       
   247   // In earlyReturn case we only want to skip throwing an exception
       
   248   // and installing an exception.
       
   249   void remove_activation(TosState state, Register ret_addr,
       
   250                          bool throw_monitor_exception = true,
       
   251                          bool install_monitor_exception = true,
       
   252                          bool notify_jvmdi = true);
       
   253 
       
   254   // At certain points in the method invocation the monitor of
       
   255   // synchronized methods hasn't been entered yet.
       
   256   // To correctly handle exceptions at these points, we set the thread local
       
   257   // variable _do_not_unlock_if_synchronized to true. The remove_activation will
       
   258   // check this flag.
       
   259   void set_do_not_unlock_if_synchronized(bool flag, Register tmp);
       
   260 
       
   261   // Debugging
       
   262   void interp_verify_oop(Register reg, TosState state, const char* file, int line);    // only if +VerifyOops && state == atos
       
   263 
       
   264   void verify_FPU(int stack_depth, TosState state = ftos) {
       
   265     // No VFP state verification is required for ARM
       
   266   }
       
   267 
       
   268   // Object locking
       
   269   void lock_object  (Register lock_reg);
       
   270   void unlock_object(Register lock_reg);
       
   271 
       
   272   // Interpreter profiling operations
       
   273   void set_method_data_pointer_for_bcp(); // Blows R0-R3/R0-R18, Rtemp, LR
       
   274   void test_method_data_pointer(Register mdp, Label& zero_continue);
       
   275   void verify_method_data_pointer();
       
   276 
       
   277   void set_mdp_data_at(Register mdp_in, int offset, Register value);
       
   278 
       
   279   // Increments mdp data. Sets bumped_count register to adjusted counter.
       
   280   void increment_mdp_data_at(Address data, Register bumped_count, bool decrement = false);
       
   281   // Increments mdp data. Sets bumped_count register to adjusted counter.
       
   282   void increment_mdp_data_at(Register mdp_in, int offset, Register bumped_count, bool decrement = false);
       
   283   void increment_mask_and_jump(Address counter_addr,
       
   284                                int increment, Address mask_addr,
       
   285                                Register scratch, Register scratch2,
       
   286                                AsmCondition cond, Label* where);
       
   287   void set_mdp_flag_at(Register mdp_in, int flag_constant);
       
   288 
       
   289   void test_mdp_data_at(Register mdp_in, int offset, Register value,
       
   290                         Register test_value_out,
       
   291                         Label& not_equal_continue);
       
   292 
       
   293   void record_klass_in_profile(Register receiver, Register mdp,
       
   294                                Register reg_tmp, bool is_virtual_call);
       
   295   void record_klass_in_profile_helper(Register receiver, Register mdp,
       
   296                                       Register reg_tmp,
       
   297                                       int start_row, Label& done, bool is_virtual_call);
       
   298 
       
   299   void update_mdp_by_offset(Register mdp_in, int offset_of_offset, Register reg_tmp);
       
   300   void update_mdp_by_offset(Register mdp_in, Register reg_offset, Register reg_tmp);
       
   301   void update_mdp_by_constant(Register mdp_in, int constant);
       
   302   void update_mdp_for_ret(Register return_bci);                   // Blows R0-R3/R0-R18, Rtemp, LR
       
   303 
       
   304   void profile_taken_branch(Register mdp, Register bumped_count); // Sets mdp, bumped_count registers, blows Rtemp.
       
   305   void profile_not_taken_branch(Register mdp);                    // Sets mdp, blows Rtemp.
       
   306 
       
   307   void profile_call(Register mdp);                                // Sets mdp, blows Rtemp.
       
   308   void profile_final_call(Register mdp);                          // Sets mdp, blows Rtemp.
       
   309   void profile_virtual_call(Register mdp, Register receiver,      // Sets mdp, blows Rtemp.
       
   310                             bool receiver_can_be_null = false);
       
   311   void profile_ret(Register mdp, Register return_bci);            // Sets mdp, blows R0-R3/R0-R18, Rtemp, LR
       
   312   void profile_null_seen(Register mdp);                           // Sets mdp.
       
   313   void profile_typecheck(Register mdp, Register klass);           // Sets mdp, blows Rtemp.
       
   314 
       
   315   void profile_typecheck_failed(Register mdp);                    // Sets mdp, blows Rtemp.
       
   316   void profile_switch_default(Register mdp);                      // Sets mdp, blows Rtemp.
       
   317 
       
   318   // Sets mdp. Blows reg_tmp1, reg_tmp2. Index could be the same as reg_tmp2.
       
   319   void profile_switch_case(Register mdp, Register index, Register reg_tmp1, Register reg_tmp2);
       
   320 
       
   321   void byteswap_u32(Register r, Register rtmp1, Register rtmp2);
       
   322 
       
   323   void inc_global_counter(address address_of_counter, int offset_in_bytes, Register tmp1, Register tmp2, bool avoid_overflow);
       
   324 
       
   325   typedef enum { NotifyJVMTI, SkipNotifyJVMTI } NotifyMethodExitMode;
       
   326 
       
   327   // support for jvmti
       
   328   void notify_method_entry();
       
   329   void notify_method_exit(TosState state, NotifyMethodExitMode mode,
       
   330                           bool native = false, Register result_lo = noreg, Register result_hi = noreg, FloatRegister result_fp = fnoreg);
       
   331 
       
   332   void trace_state(const char* msg) PRODUCT_RETURN;
       
   333 
       
   334 void get_method_counters(Register method,
       
   335                          Register Rcounters,
       
   336                          Label& skip,
       
   337                          bool saveRegs = false,
       
   338                          Register reg1 = noreg,
       
   339                          Register reg2 = noreg,
       
   340                          Register reg3 = noreg);
       
   341 };
       
   342 
       
   343 #endif // CPU_ARM_VM_INTERP_MASM_ARM_HPP