hotspot/src/cpu/x86/vm/cppInterpreter_x86.cpp
changeset 24018 77b156916bab
parent 23844 0c29a324ae14
child 25950 b5c40ed1d349
equal deleted inserted replaced
24016:2927072ed5fb 24018:77b156916bab
  2340   to_fill->_self_link = to_fill;
  2340   to_fill->_self_link = to_fill;
  2341   assert(stack >= to_fill->_stack_limit && stack < to_fill->_stack_base,
  2341   assert(stack >= to_fill->_stack_limit && stack < to_fill->_stack_base,
  2342          "Stack top out of range");
  2342          "Stack top out of range");
  2343 }
  2343 }
  2344 
  2344 
  2345 int AbstractInterpreter::layout_activation(Method* method,
  2345 
  2346                                            int tempcount,  //
  2346 static int frame_size_helper(int max_stack,
  2347                                            int popframe_extra_args,
  2347                              int tempcount,
  2348                                            int moncount,
  2348                              int moncount,
  2349                                            int caller_actual_parameters,
  2349                              int callee_param_count,
  2350                                            int callee_param_count,
  2350                              int callee_locals,
  2351                                            int callee_locals,
  2351                              bool is_top_frame,
  2352                                            frame* caller,
  2352                              int& monitor_size,
  2353                                            frame* interpreter_frame,
  2353                              int& full_frame_size) {
  2354                                            bool is_top_frame,
  2354   int extra_locals_size = (callee_locals - callee_param_count) * BytesPerWord;
  2355                                            bool is_bottom_frame) {
  2355   monitor_size = sizeof(BasicObjectLock) * moncount;
  2356 
  2356 
  2357   assert(popframe_extra_args == 0, "FIX ME");
  2357   // First calculate the frame size without any java expression stack
  2358   // NOTE this code must exactly mimic what InterpreterGenerator::generate_compute_interpreter_state()
  2358   int short_frame_size = size_activation_helper(extra_locals_size,
  2359   // does as far as allocating an interpreter frame.
  2359                                                 monitor_size);
  2360   // If interpreter_frame!=NULL, set up the method, locals, and monitors.
  2360 
  2361   // The frame interpreter_frame, if not NULL, is guaranteed to be the right size,
  2361   // Now with full size expression stack
  2362   // as determined by a previous call to this method.
  2362   full_frame_size = short_frame_size + max_stack * BytesPerWord;
  2363   // It is also guaranteed to be walkable even though it is in a skeletal state
  2363 
       
  2364   // and now with only live portion of the expression stack
       
  2365   short_frame_size = short_frame_size + tempcount * BytesPerWord;
       
  2366 
       
  2367   // the size the activation is right now. Only top frame is full size
       
  2368   int frame_size = (is_top_frame ? full_frame_size : short_frame_size);
       
  2369   return frame_size;
       
  2370 }
       
  2371 
       
  2372 int AbstractInterpreter::size_activation(int max_stack,
       
  2373                                          int tempcount,
       
  2374                                          int extra_args,
       
  2375                                          int moncount,
       
  2376                                          int callee_param_count,
       
  2377                                          int callee_locals,
       
  2378                                          bool is_top_frame) {
       
  2379   assert(extra_args == 0, "FIX ME");
  2364   // NOTE: return size is in words not bytes
  2380   // NOTE: return size is in words not bytes
  2365   // NOTE: tempcount is the current size of the java expression stack. For top most
       
  2366   //       frames we will allocate a full sized expression stack and not the curback
       
  2367   //       version that non-top frames have.
       
  2368 
  2381 
  2369   // Calculate the amount our frame will be adjust by the callee. For top frame
  2382   // Calculate the amount our frame will be adjust by the callee. For top frame
  2370   // this is zero.
  2383   // this is zero.
  2371 
  2384 
  2372   // NOTE: ia64 seems to do this wrong (or at least backwards) in that it
  2385   // NOTE: ia64 seems to do this wrong (or at least backwards) in that it
  2373   // calculates the extra locals based on itself. Not what the callee does
  2386   // calculates the extra locals based on itself. Not what the callee does
  2374   // to it. So it ignores last_frame_adjust value. Seems suspicious as far
  2387   // to it. So it ignores last_frame_adjust value. Seems suspicious as far
  2375   // as getting sender_sp correct.
  2388   // as getting sender_sp correct.
  2376 
  2389 
  2377   int extra_locals_size = (callee_locals - callee_param_count) * BytesPerWord;
  2390   int unused_monitor_size = 0;
  2378   int monitor_size = sizeof(BasicObjectLock) * moncount;
  2391   int unused_full_frame_size = 0;
  2379 
  2392   return frame_size_helper(max_stack, tempcount, moncount, callee_param_count, callee_locals,
  2380   // First calculate the frame size without any java expression stack
  2393                            is_top_frame, unused_monitor_size, unused_full_frame_size)/BytesPerWord;
  2381   int short_frame_size = size_activation_helper(extra_locals_size,
  2394 }
  2382                                                 monitor_size);
  2395 
  2383 
  2396 void AbstractInterpreter::layout_activation(Method* method,
  2384   // Now with full size expression stack
  2397                                             int tempcount,  //
  2385   int full_frame_size = short_frame_size + method->max_stack() * BytesPerWord;
  2398                                             int popframe_extra_args,
  2386 
  2399                                             int moncount,
  2387   // and now with only live portion of the expression stack
  2400                                             int caller_actual_parameters,
  2388   short_frame_size = short_frame_size + tempcount * BytesPerWord;
  2401                                             int callee_param_count,
  2389 
  2402                                             int callee_locals,
  2390   // the size the activation is right now. Only top frame is full size
  2403                                             frame* caller,
  2391   int frame_size = (is_top_frame ? full_frame_size : short_frame_size);
  2404                                             frame* interpreter_frame,
  2392 
  2405                                             bool is_top_frame,
  2393   if (interpreter_frame != NULL) {
  2406                                             bool is_bottom_frame) {
       
  2407 
       
  2408   assert(popframe_extra_args == 0, "FIX ME");
       
  2409   // NOTE this code must exactly mimic what InterpreterGenerator::generate_compute_interpreter_state()
       
  2410   // does as far as allocating an interpreter frame.
       
  2411   // Set up the method, locals, and monitors.
       
  2412   // The frame interpreter_frame is guaranteed to be the right size,
       
  2413   // as determined by a previous call to the size_activation() method.
       
  2414   // It is also guaranteed to be walkable even though it is in a skeletal state
       
  2415   // NOTE: tempcount is the current size of the java expression stack. For top most
       
  2416   //       frames we will allocate a full sized expression stack and not the curback
       
  2417   //       version that non-top frames have.
       
  2418 
       
  2419   int monitor_size = 0;
       
  2420   int full_frame_size = 0;
       
  2421   int frame_size = frame_size_helper(method->max_stack(), tempcount, moncount, callee_param_count, callee_locals,
       
  2422                                      is_top_frame, monitor_size, full_frame_size);
       
  2423 
  2394 #ifdef ASSERT
  2424 #ifdef ASSERT
  2395     assert(caller->unextended_sp() == interpreter_frame->interpreter_frame_sender_sp(), "Frame not properly walkable");
  2425   assert(caller->unextended_sp() == interpreter_frame->interpreter_frame_sender_sp(), "Frame not properly walkable");
  2396 #endif
  2426 #endif
  2397 
  2427 
  2398     // MUCHO HACK
  2428   // MUCHO HACK
  2399 
  2429 
  2400     intptr_t* frame_bottom = (intptr_t*) ((intptr_t)interpreter_frame->sp() - (full_frame_size - frame_size));
  2430   intptr_t* frame_bottom = (intptr_t*) ((intptr_t)interpreter_frame->sp() - (full_frame_size - frame_size));
  2401 
  2431 
  2402     /* Now fillin the interpreterState object */
  2432   /* Now fillin the interpreterState object */
  2403 
  2433 
  2404     // The state object is the first thing on the frame and easily located
  2434   // The state object is the first thing on the frame and easily located
  2405 
  2435 
  2406     interpreterState cur_state = (interpreterState) ((intptr_t)interpreter_frame->fp() - sizeof(BytecodeInterpreter));
  2436   interpreterState cur_state = (interpreterState) ((intptr_t)interpreter_frame->fp() - sizeof(BytecodeInterpreter));
  2407 
  2437 
  2408 
  2438 
  2409     // Find the locals pointer. This is rather simple on x86 because there is no
  2439   // Find the locals pointer. This is rather simple on x86 because there is no
  2410     // confusing rounding at the callee to account for. We can trivially locate
  2440   // confusing rounding at the callee to account for. We can trivially locate
  2411     // our locals based on the current fp().
  2441   // our locals based on the current fp().
  2412     // Note: the + 2 is for handling the "static long no_params() method" issue.
  2442   // Note: the + 2 is for handling the "static long no_params() method" issue.
  2413     // (too bad I don't really remember that issue well...)
  2443   // (too bad I don't really remember that issue well...)
  2414 
  2444 
  2415     intptr_t* locals;
  2445   intptr_t* locals;
  2416     // If the caller is interpreted we need to make sure that locals points to the first
  2446   // If the caller is interpreted we need to make sure that locals points to the first
  2417     // argument that the caller passed and not in an area where the stack might have been extended.
  2447   // argument that the caller passed and not in an area where the stack might have been extended.
  2418     // because the stack to stack to converter needs a proper locals value in order to remove the
  2448   // because the stack to stack to converter needs a proper locals value in order to remove the
  2419     // arguments from the caller and place the result in the proper location. Hmm maybe it'd be
  2449   // arguments from the caller and place the result in the proper location. Hmm maybe it'd be
  2420     // simpler if we simply stored the result in the BytecodeInterpreter object and let the c++ code
  2450   // simpler if we simply stored the result in the BytecodeInterpreter object and let the c++ code
  2421     // adjust the stack?? HMMM QQQ
  2451   // adjust the stack?? HMMM QQQ
  2422     //
  2452   //
  2423     if (caller->is_interpreted_frame()) {
  2453   if (caller->is_interpreted_frame()) {
  2424       // locals must agree with the caller because it will be used to set the
  2454     // locals must agree with the caller because it will be used to set the
  2425       // caller's tos when we return.
  2455     // caller's tos when we return.
  2426       interpreterState prev  = caller->get_interpreterState();
  2456     interpreterState prev  = caller->get_interpreterState();
  2427       // stack() is prepushed.
  2457     // stack() is prepushed.
  2428       locals = prev->stack() + method->size_of_parameters();
  2458     locals = prev->stack() + method->size_of_parameters();
  2429       // locals = caller->unextended_sp() + (method->size_of_parameters() - 1);
  2459     // locals = caller->unextended_sp() + (method->size_of_parameters() - 1);
  2430       if (locals != interpreter_frame->fp() + frame::sender_sp_offset + (method->max_locals() - 1) + 2) {
  2460     if (locals != interpreter_frame->fp() + frame::sender_sp_offset + (method->max_locals() - 1) + 2) {
  2431         // os::breakpoint();
  2461       // os::breakpoint();
  2432       }
       
  2433     } else {
       
  2434       // this is where a c2i would have placed locals (except for the +2)
       
  2435       locals = interpreter_frame->fp() + frame::sender_sp_offset + (method->max_locals() - 1) + 2;
       
  2436     }
  2462     }
  2437 
  2463   } else {
  2438     intptr_t* monitor_base = (intptr_t*) cur_state;
  2464     // this is where a c2i would have placed locals (except for the +2)
  2439     intptr_t* stack_base = (intptr_t*) ((intptr_t) monitor_base - monitor_size);
  2465     locals = interpreter_frame->fp() + frame::sender_sp_offset + (method->max_locals() - 1) + 2;
  2440     /* +1 because stack is always prepushed */
  2466   }
  2441     intptr_t* stack = (intptr_t*) ((intptr_t) stack_base - (tempcount + 1) * BytesPerWord);
  2467 
  2442 
  2468   intptr_t* monitor_base = (intptr_t*) cur_state;
  2443 
  2469   intptr_t* stack_base = (intptr_t*) ((intptr_t) monitor_base - monitor_size);
  2444     BytecodeInterpreter::layout_interpreterState(cur_state,
  2470   /* +1 because stack is always prepushed */
  2445                                           caller,
  2471   intptr_t* stack = (intptr_t*) ((intptr_t) stack_base - (tempcount + 1) * BytesPerWord);
  2446                                           interpreter_frame,
  2472 
  2447                                           method,
  2473 
  2448                                           locals,
  2474   BytecodeInterpreter::layout_interpreterState(cur_state,
  2449                                           stack,
  2475                                                caller,
  2450                                           stack_base,
  2476                                                interpreter_frame,
  2451                                           monitor_base,
  2477                                                method,
  2452                                           frame_bottom,
  2478                                                locals,
  2453                                           is_top_frame);
  2479                                                stack,
  2454 
  2480                                                stack_base,
  2455     // BytecodeInterpreter::pd_layout_interpreterState(cur_state, interpreter_return_address, interpreter_frame->fp());
  2481                                                monitor_base,
  2456   }
  2482                                                frame_bottom,
  2457   return frame_size/BytesPerWord;
  2483                                                is_top_frame);
       
  2484 
       
  2485   // BytecodeInterpreter::pd_layout_interpreterState(cur_state, interpreter_return_address, interpreter_frame->fp());
  2458 }
  2486 }
  2459 
  2487 
  2460 bool AbstractInterpreter::can_be_compiled(methodHandle m) {
  2488 bool AbstractInterpreter::can_be_compiled(methodHandle m) {
  2461   switch (method_kind(m)) {
  2489   switch (method_kind(m)) {
  2462     case Interpreter::java_lang_math_sin     : // fall thru
  2490     case Interpreter::java_lang_math_sin     : // fall thru