src/cpu/sparc/vm/cppInterpreter_sparc.cpp

Print this page
rev 4376 : 8010460: Interpreter on some platforms loads ConstMethod::_max_stack and misses extra stack slots for JSR 292
Summary: ConstMethod::max_stack() doesn't account for JSR 292 appendix.
Reviewed-by:


1042   // G2_thread - valid? (C1 only??)
1043   // "prev_state" - contains any previous frame manager state which we must save a link
1044   //
1045   // On return
1046   // "state" is a pointer to the newly allocated  state object. We must allocate and initialize
1047   // a new interpretState object and the method expression stack.
1048 
1049   assert_different_registers(state, prev_state);
1050   assert_different_registers(prev_state, G3_scratch);
1051   const Register Gtmp = G3_scratch;
1052   const Address constMethod       (G5_method, 0, in_bytes(Method::const_offset()));
1053   const Address access_flags      (G5_method, 0, in_bytes(Method::access_flags_offset()));
1054 
1055   // slop factor is two extra slots on the expression stack so that
1056   // we always have room to store a result when returning from a call without parameters
1057   // that returns a result.
1058 
1059   const int slop_factor = 2*wordSize;
1060 
1061   const int fixed_size = ((sizeof(BytecodeInterpreter) + slop_factor) >> LogBytesPerWord) + // what is the slop factor?
1062                          //6815692//Method::extra_stack_words() +  // extra push slots for MH adapters
1063                          frame::memory_parameter_word_sp_offset +  // register save area + param window
1064                          (native ?  frame::interpreter_frame_extra_outgoing_argument_words : 0); // JNI, class
1065 
1066   // XXX G5_method valid
1067 
1068   // Now compute new frame size
1069 
1070   if (native) {
1071     const Register RconstMethod = Gtmp;
1072     const Address size_of_parameters(RconstMethod, 0, in_bytes(ConstMethod::size_of_parameters_offset()));
1073     __ ld_ptr(constMethod, RconstMethod);
1074     __ lduh( size_of_parameters, Gtmp );
1075     __ calc_mem_param_words(Gtmp, Gtmp);     // space for native call parameters passed on the stack in words
1076   } else {
1077     // Full size expression stack
1078     __ ld_ptr(constMethod, Gtmp);
1079     __ lduh(Gtmp, in_bytes(ConstMethod::max_stack_offset()), Gtmp);
1080   }
1081   __ add(Gtmp, fixed_size, Gtmp);           // plus the fixed portion
1082 


2061 static int size_activation_helper(int callee_extra_locals, int max_stack, int monitor_size) {
2062 
2063   // Figure out the size of an interpreter frame (in words) given that we have a fully allocated
2064   // expression stack, the callee will have callee_extra_locals (so we can account for
2065   // frame extension) and monitor_size for monitors. Basically we need to calculate
2066   // this exactly like generate_fixed_frame/generate_compute_interpreter_state.
2067   //
2068   //
2069   // The big complicating thing here is that we must ensure that the stack stays properly
2070   // aligned. This would be even uglier if monitor size wasn't modulo what the stack
2071   // needs to be aligned for). We are given that the sp (fp) is already aligned by
2072   // the caller so we must ensure that it is properly aligned for our callee.
2073   //
2074   // Ths c++ interpreter always makes sure that we have a enough extra space on the
2075   // stack at all times to deal with the "stack long no_params()" method issue. This
2076   // is "slop_factor" here.
2077   const int slop_factor = 2;
2078 
2079   const int fixed_size = sizeof(BytecodeInterpreter)/wordSize +           // interpreter state object
2080                          frame::memory_parameter_word_sp_offset;   // register save area + param window
2081   const int extra_stack = 0; //6815692//Method::extra_stack_entries();
2082   return (round_to(max_stack +
2083                    extra_stack +
2084                    slop_factor +
2085                    fixed_size +
2086                    monitor_size +
2087                    (callee_extra_locals * Interpreter::stackElementWords), WordsPerLong));
2088 
2089 }
2090 
2091 int AbstractInterpreter::size_top_interpreter_activation(Method* method) {
2092 
2093   // See call_stub code
2094   int call_stub_size  = round_to(7 + frame::memory_parameter_word_sp_offset,
2095                                  WordsPerLong);    // 7 + register save area
2096 
2097   // Save space for one monitor to get into the interpreted method in case
2098   // the method is synchronized
2099   int monitor_size    = method->is_synchronized() ?
2100                                 1*frame::interpreter_frame_monitor_size() : 0;
2101   return size_activation_helper(method->max_locals(), method->max_stack(),
2102                                  monitor_size) + call_stub_size;
2103 }


2150   // skeletal already places a useful value here and this doesn't account
2151   // for alignment so don't bother.
2152   // *current->register_addr(I5_savedSP) =     (intptr_t) locals - (method->size_of_parameters() - 1);
2153 
2154   if (caller->is_interpreted_frame()) {
2155     interpreterState prev  = caller->get_interpreterState();
2156     to_fill->_prev_link = prev;
2157     // Make the prev callee look proper
2158     prev->_result._to_call._callee = method;
2159     if (*prev->_bcp == Bytecodes::_invokeinterface) {
2160       prev->_result._to_call._bcp_advance = 5;
2161     } else {
2162       prev->_result._to_call._bcp_advance = 3;
2163     }
2164   }
2165   to_fill->_oop_temp = NULL;
2166   to_fill->_stack_base = stack_base;
2167   // Need +1 here because stack_base points to the word just above the first expr stack entry
2168   // and stack_limit is supposed to point to the word just below the last expr stack entry.
2169   // See generate_compute_interpreter_state.
2170   int extra_stack = 0; //6815692//Method::extra_stack_entries();
2171   to_fill->_stack_limit = stack_base - (method->max_stack() + 1 + extra_stack);
2172   to_fill->_monitor_base = (BasicObjectLock*) monitor_base;
2173 
2174   // sparc specific
2175   to_fill->_frame_bottom = frame_bottom;
2176   to_fill->_self_link = to_fill;
2177 #ifdef ASSERT
2178   to_fill->_native_fresult = 123456.789;
2179   to_fill->_native_lresult = CONST64(0xdeadcafedeafcafe);
2180 #endif
2181 }
2182 
2183 void BytecodeInterpreter::pd_layout_interpreterState(interpreterState istate, address last_Java_pc, intptr_t* last_Java_fp) {
2184   istate->_last_Java_pc = (intptr_t*) last_Java_pc;
2185 }
2186 
2187 
2188 int AbstractInterpreter::layout_activation(Method* method,
2189                                            int tempcount, // Number of slots on java expression stack in use
2190                                            int popframe_extra_args,
2191                                            int moncount,  // Number of active monitors




1042   // G2_thread - valid? (C1 only??)
1043   // "prev_state" - contains any previous frame manager state which we must save a link
1044   //
1045   // On return
1046   // "state" is a pointer to the newly allocated  state object. We must allocate and initialize
1047   // a new interpretState object and the method expression stack.
1048 
1049   assert_different_registers(state, prev_state);
1050   assert_different_registers(prev_state, G3_scratch);
1051   const Register Gtmp = G3_scratch;
1052   const Address constMethod       (G5_method, 0, in_bytes(Method::const_offset()));
1053   const Address access_flags      (G5_method, 0, in_bytes(Method::access_flags_offset()));
1054 
1055   // slop factor is two extra slots on the expression stack so that
1056   // we always have room to store a result when returning from a call without parameters
1057   // that returns a result.
1058 
1059   const int slop_factor = 2*wordSize;
1060 
1061   const int fixed_size = ((sizeof(BytecodeInterpreter) + slop_factor) >> LogBytesPerWord) + // what is the slop factor?

1062                          frame::memory_parameter_word_sp_offset +  // register save area + param window
1063                          (native ?  frame::interpreter_frame_extra_outgoing_argument_words : 0); // JNI, class
1064 
1065   // XXX G5_method valid
1066 
1067   // Now compute new frame size
1068 
1069   if (native) {
1070     const Register RconstMethod = Gtmp;
1071     const Address size_of_parameters(RconstMethod, 0, in_bytes(ConstMethod::size_of_parameters_offset()));
1072     __ ld_ptr(constMethod, RconstMethod);
1073     __ lduh( size_of_parameters, Gtmp );
1074     __ calc_mem_param_words(Gtmp, Gtmp);     // space for native call parameters passed on the stack in words
1075   } else {
1076     // Full size expression stack
1077     __ ld_ptr(constMethod, Gtmp);
1078     __ lduh(Gtmp, in_bytes(ConstMethod::max_stack_offset()), Gtmp);
1079   }
1080   __ add(Gtmp, fixed_size, Gtmp);           // plus the fixed portion
1081 


2060 static int size_activation_helper(int callee_extra_locals, int max_stack, int monitor_size) {
2061 
2062   // Figure out the size of an interpreter frame (in words) given that we have a fully allocated
2063   // expression stack, the callee will have callee_extra_locals (so we can account for
2064   // frame extension) and monitor_size for monitors. Basically we need to calculate
2065   // this exactly like generate_fixed_frame/generate_compute_interpreter_state.
2066   //
2067   //
2068   // The big complicating thing here is that we must ensure that the stack stays properly
2069   // aligned. This would be even uglier if monitor size wasn't modulo what the stack
2070   // needs to be aligned for). We are given that the sp (fp) is already aligned by
2071   // the caller so we must ensure that it is properly aligned for our callee.
2072   //
2073   // Ths c++ interpreter always makes sure that we have a enough extra space on the
2074   // stack at all times to deal with the "stack long no_params()" method issue. This
2075   // is "slop_factor" here.
2076   const int slop_factor = 2;
2077 
2078   const int fixed_size = sizeof(BytecodeInterpreter)/wordSize +           // interpreter state object
2079                          frame::memory_parameter_word_sp_offset;   // register save area + param window

2080   return (round_to(max_stack +

2081                    slop_factor +
2082                    fixed_size +
2083                    monitor_size +
2084                    (callee_extra_locals * Interpreter::stackElementWords), WordsPerLong));
2085 
2086 }
2087 
2088 int AbstractInterpreter::size_top_interpreter_activation(Method* method) {
2089 
2090   // See call_stub code
2091   int call_stub_size  = round_to(7 + frame::memory_parameter_word_sp_offset,
2092                                  WordsPerLong);    // 7 + register save area
2093 
2094   // Save space for one monitor to get into the interpreted method in case
2095   // the method is synchronized
2096   int monitor_size    = method->is_synchronized() ?
2097                                 1*frame::interpreter_frame_monitor_size() : 0;
2098   return size_activation_helper(method->max_locals(), method->max_stack(),
2099                                  monitor_size) + call_stub_size;
2100 }


2147   // skeletal already places a useful value here and this doesn't account
2148   // for alignment so don't bother.
2149   // *current->register_addr(I5_savedSP) =     (intptr_t) locals - (method->size_of_parameters() - 1);
2150 
2151   if (caller->is_interpreted_frame()) {
2152     interpreterState prev  = caller->get_interpreterState();
2153     to_fill->_prev_link = prev;
2154     // Make the prev callee look proper
2155     prev->_result._to_call._callee = method;
2156     if (*prev->_bcp == Bytecodes::_invokeinterface) {
2157       prev->_result._to_call._bcp_advance = 5;
2158     } else {
2159       prev->_result._to_call._bcp_advance = 3;
2160     }
2161   }
2162   to_fill->_oop_temp = NULL;
2163   to_fill->_stack_base = stack_base;
2164   // Need +1 here because stack_base points to the word just above the first expr stack entry
2165   // and stack_limit is supposed to point to the word just below the last expr stack entry.
2166   // See generate_compute_interpreter_state.
2167   to_fill->_stack_limit = stack_base - (method->max_stack() + 1);

2168   to_fill->_monitor_base = (BasicObjectLock*) monitor_base;
2169 
2170   // sparc specific
2171   to_fill->_frame_bottom = frame_bottom;
2172   to_fill->_self_link = to_fill;
2173 #ifdef ASSERT
2174   to_fill->_native_fresult = 123456.789;
2175   to_fill->_native_lresult = CONST64(0xdeadcafedeafcafe);
2176 #endif
2177 }
2178 
2179 void BytecodeInterpreter::pd_layout_interpreterState(interpreterState istate, address last_Java_pc, intptr_t* last_Java_fp) {
2180   istate->_last_Java_pc = (intptr_t*) last_Java_pc;
2181 }
2182 
2183 
2184 int AbstractInterpreter::layout_activation(Method* method,
2185                                            int tempcount, // Number of slots on java expression stack in use
2186                                            int popframe_extra_args,
2187                                            int moncount,  // Number of active monitors