changeset 4174:79c91d220d73

Use callee save area to model the saved rbp register. Remove various hacks that added the saved area size in native code.
author Christian Wimmer <Christian.Wimmer@Oracle.com>
date Thu, 29 Dec 2011 16:07:35 -0800
parents 15b9402dc018
children ea49d7abeb05
files graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotRegisterConfig.java graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotTarget.java graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotXirGenerator.java src/share/vm/graal/graalCodeInstaller.cpp src/share/vm/graal/graalCodeInstaller.hpp src/share/vm/graal/graalEnv.cpp
diffstat 6 files changed, 34 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotRegisterConfig.java	Thu Dec 29 15:47:15 2011 -0800
+++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotRegisterConfig.java	Thu Dec 29 16:07:35 2011 -0800
@@ -88,7 +88,7 @@
         if (globalStubConfig) {
             registerSaveArea = new CiCalleeSaveLayout(0, -1, 8, rsaRegs);
         } else {
-            registerSaveArea = new CiCalleeSaveLayout(0, 0, 0, new CiRegister[0]);
+            registerSaveArea = new CiCalleeSaveLayout(0, 8, 8, new CiRegister[0]);
         }
 
         attributesMap = RiRegisterAttributes.createMap(this, AMD64.allRegisters);
@@ -153,8 +153,7 @@
             }
 
             if (locations[i] == null) {
-                // we need to adjust for the frame pointer stored on the stack, which shifts incoming arguments by one slot
-                locations[i] = CiStackSlot.get(kind.stackKind(), currentStackIndex + (type.out ? 0 : 1), !type.out);
+                locations[i] = CiStackSlot.get(kind.stackKind(), currentStackIndex, !type.out);
                 currentStackIndex += target.spillSlots(kind);
             }
         }
--- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotTarget.java	Thu Dec 29 15:47:15 2011 -0800
+++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotTarget.java	Thu Dec 29 16:07:35 2011 -0800
@@ -25,17 +25,12 @@
 import com.sun.cri.ci.*;
 
 /**
- * HotSpot-specific CiTarget that provides the correct stack frame size alignment.
+ * HotSpot-specific CiTarget.
+ * TODO currently empty class, so check if it can be deleted.
  */
 public class HotSpotTarget extends CiTarget {
 
     public HotSpotTarget(CiArchitecture arch, boolean isMP, int spillSlotSize, int stackAlignment, int pageSize, int cacheAlignment, boolean inlineObjects) {
         super(arch, isMP, spillSlotSize, stackAlignment, pageSize, cacheAlignment, inlineObjects, true, true);
     }
-
-    @Override
-    public int alignFrameSize(int frameSize) {
-        // account for the stored rbp value
-        return super.alignFrameSize(frameSize + wordSize) - wordSize;
-    }
 }
--- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotXirGenerator.java	Thu Dec 29 15:47:15 2011 -0800
+++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotXirGenerator.java	Thu Dec 29 16:07:35 2011 -0800
@@ -129,6 +129,8 @@
             asm.stackOverflowCheck();
             asm.push(framePointer);
             asm.mov(framePointer, stackPointer);
+            // Compensate for the push of framePointer (the XIR instruction pushFrame is not flexible enough to reduce the frame size, wait until XIR goes away to fix this).
+            asm.add(stackPointer, stackPointer,  asm.i(8));
             asm.pushFrame();
 
             // -- out of line -------------------------------------------------------
@@ -169,9 +171,10 @@
         protected XirTemplate create(CiXirAssembler asm, long flags) {
             asm.restart(CiKind.Void);
             XirOperand framePointer = asm.createRegisterTemp("frame pointer", target.wordKind, AMD64.rbp);
+            XirOperand stackPointer = asm.createRegisterTemp("stack pointer", target.wordKind, AMD64.rsp);
 
             asm.popFrame();
-            asm.pop(framePointer);
+            asm.pload(CiKind.Long, framePointer, stackPointer, asm.i(-8), false);
 
             if (GraalOptions.GenSafepoints) {
                 XirOperand temp = asm.createRegisterTemp("temp", target.wordKind, AMD64.r10);
--- a/src/share/vm/graal/graalCodeInstaller.cpp	Thu Dec 29 15:47:15 2011 -0800
+++ b/src/share/vm/graal/graalCodeInstaller.cpp	Thu Dec 29 16:07:35 2011 -0800
@@ -68,8 +68,8 @@
 }
 
 // creates a hotspot oop map out of the byte arrays provided by CiDebugInfo
-static OopMap* create_oop_map(jint frame_size, jint parameter_count, oop debug_info) {
-  OopMap* map = new OopMap(frame_size, parameter_count);
+static OopMap* create_oop_map(jint total_frame_size, jint parameter_count, oop debug_info) {
+  OopMap* map = new OopMap(total_frame_size, parameter_count);
   oop register_map = (oop) CiDebugInfo::registerRefMap(debug_info);
   oop frame_map = (oop) CiDebugInfo::frameRefMap(debug_info);
 
@@ -87,28 +87,22 @@
     }
   }
 
-  if (frame_size > 0) {
-    assert(GraalBitMap::size(frame_map) == frame_size / HeapWordSize, "unexpected frame_map length");
-
-    for (jint i = 0; i < frame_size / HeapWordSize; i++) {
-      bool is_oop = is_bit_set(frame_map, i);
-      // hotspot stack slots are 4 bytes
-      VMReg reg = VMRegImpl::stack2reg(i * 2);
-      if (is_oop) {
-        map->set_oop(reg);
-      } else {
-        map->set_value(reg);
-      }
+  for (jint i = 0; i < GraalBitMap::size(frame_map); i++) {
+    bool is_oop = is_bit_set(frame_map, i);
+    // hotspot stack slots are 4 bytes
+    VMReg reg = VMRegImpl::stack2reg(i * 2);
+    if (is_oop) {
+      map->set_oop(reg);
+    } else {
+      map->set_value(reg);
     }
-  } else {
-    assert(frame_map == NULL || GraalBitMap::size(frame_map) == 0, "cannot have frame_map for frames with size 0");
   }
 
   return map;
 }
 
 // TODO: finish this - graal doesn't provide any scope values at the moment
-static ScopeValue* get_hotspot_value(oop value, int frame_size, GrowableArray<ScopeValue*>* objects, ScopeValue* &second) {
+static ScopeValue* get_hotspot_value(oop value, int total_frame_size, GrowableArray<ScopeValue*>* objects, ScopeValue* &second) {
   second = NULL;
   if (value == CiValue::IllegalValue()) {
     return new LocationValue(Location::new_stk_loc(Location::invalid, 0));
@@ -158,7 +152,7 @@
     if (index >= 0) {
       value = new LocationValue(Location::new_stk_loc(locationType, index * HeapWordSize));
     } else {
-      value = new LocationValue(Location::new_stk_loc(locationType, -(index * HeapWordSize) + frame_size));
+      value = new LocationValue(Location::new_stk_loc(locationType, -((index + 1) * HeapWordSize) + total_frame_size));
     }
     if (type == T_DOUBLE || type == T_LONG) {
       second = value;
@@ -204,7 +198,7 @@
 
     for (jint i = 0; i < values->length(); i++) {
       ScopeValue* cur_second = NULL;
-      ScopeValue* value = get_hotspot_value(((oop*) values->base(T_OBJECT))[i], frame_size, objects, cur_second);
+      ScopeValue* value = get_hotspot_value(((oop*) values->base(T_OBJECT))[i], total_frame_size, objects, cur_second);
       
       if (cur_second != NULL) {
         sv->field_values()->append(cur_second);
@@ -221,15 +215,15 @@
   return NULL;
 }
 
-static MonitorValue* get_monitor_value(oop value, int frame_size, GrowableArray<ScopeValue*>* objects) {
+static MonitorValue* get_monitor_value(oop value, int total_frame_size, GrowableArray<ScopeValue*>* objects) {
   guarantee(value->is_a(CiMonitorValue::klass()), "Monitors must be of type CiMonitorValue");
 
   ScopeValue* second = NULL;
-  ScopeValue* owner_value = get_hotspot_value(CiMonitorValue::owner(value), frame_size, objects, second);
+  ScopeValue* owner_value = get_hotspot_value(CiMonitorValue::owner(value), total_frame_size, objects, second);
   assert(second == NULL, "monitor cannot occupy two stack slots");
 
-  ScopeValue* lock_data_value = get_hotspot_value(CiMonitorValue::lockData(value), frame_size, objects, second);
-  assert(second == NULL, "monitor cannot occupy two stack slots");
+  ScopeValue* lock_data_value = get_hotspot_value(CiMonitorValue::lockData(value), total_frame_size, objects, second);
+  assert(second == lock_data_value, "monitor is LONG value that occupies two stack slots");
   assert(lock_data_value->is_location(), "invalid monitor location");
   Location lock_data_loc = ((LocationValue*)lock_data_value)->location();
 
@@ -281,7 +275,7 @@
     process_exception_handlers();
   }
 
-  int stack_slots = (_frame_size / HeapWordSize) + 2; // conversion to words, need to add two slots for ret address and frame pointer
+  int stack_slots = _total_frame_size / HeapWordSize; // conversion to words
   methodHandle method = getMethodFromHotSpotMethod(HotSpotTargetMethod::method(JNIHandles::resolve(target_method_obj))); 
   {
     nm = GraalEnv::register_method(method, -1, &_offsets, _custom_stack_area_offset, &buffer, stack_slots, _debug_recorder->_oopmaps, &_exception_handler_table,
@@ -323,7 +317,8 @@
 
   _code = (arrayOop) CiTargetMethod::targetCode(_citarget_method);
   _code_size = CiTargetMethod::targetCodeSize(_citarget_method);
-  _frame_size = CiTargetMethod::frameSize(_citarget_method);
+  // The frame size we get from the target method does not include the return address, so add one word for it here.
+  _total_frame_size = CiTargetMethod::frameSize(_citarget_method) + HeapWordSize;
   _custom_stack_area_offset = CiTargetMethod::customStackAreaOffset(_citarget_method);
 
 
@@ -511,19 +506,19 @@
       oop value = ((oop*) values->base(T_OBJECT))[i];
 
       if (i < local_count) {
-        ScopeValue* first = get_hotspot_value(value, _frame_size, objects, second);
+        ScopeValue* first = get_hotspot_value(value, _total_frame_size, objects, second);
         if (second != NULL) {
           locals->append(second);
         }
         locals->append(first);
       } else if (i < local_count + expression_count) {
-        ScopeValue* first = get_hotspot_value(value, _frame_size, objects, second);
+        ScopeValue* first = get_hotspot_value(value, _total_frame_size, objects, second);
         if (second != NULL) {
           expressions->append(second);
         }
         expressions->append(first);
       } else {
-        monitors->append(get_monitor_value(value, _frame_size, objects));
+        monitors->append(get_monitor_value(value, _total_frame_size, objects));
       }
       if (second != NULL) {
         i++;
@@ -555,7 +550,7 @@
 
   // address instruction = _instructions->start() + pc_offset;
   // jint next_pc_offset = Assembler::locate_next_instruction(instruction) - _instructions->start();
-  _debug_recorder->add_safepoint(pc_offset, create_oop_map(_frame_size, _parameter_count, debug_info));
+  _debug_recorder->add_safepoint(pc_offset, create_oop_map(_total_frame_size, _parameter_count, debug_info));
 
   oop code_pos = CiDebugInfo::codePos(debug_info);
   record_scope(pc_offset, code_pos, new GrowableArray<ScopeValue*>());
@@ -666,7 +661,7 @@
   }
 
   if (debug_info != NULL) {
-    _debug_recorder->add_safepoint(next_pc_offset, create_oop_map(_frame_size, _parameter_count, debug_info));
+    _debug_recorder->add_safepoint(next_pc_offset, create_oop_map(_total_frame_size, _parameter_count, debug_info));
     oop code_pos = CiDebugInfo::codePos(debug_info);
     record_scope(next_pc_offset, code_pos, new GrowableArray<ScopeValue*>());
   }
--- a/src/share/vm/graal/graalCodeInstaller.hpp	Thu Dec 29 15:47:15 2011 -0800
+++ b/src/share/vm/graal/graalCodeInstaller.hpp	Thu Dec 29 16:07:35 2011 -0800
@@ -61,7 +61,7 @@
 
   arrayOop      _code;
   jint          _code_size;
-  jint          _frame_size;
+  jint          _total_frame_size;
   jint          _custom_stack_area_offset;
   jint          _parameter_count;
   jint          _constants_size;
--- a/src/share/vm/graal/graalEnv.cpp	Thu Dec 29 15:47:15 2011 -0800
+++ b/src/share/vm/graal/graalEnv.cpp	Thu Dec 29 16:07:35 2011 -0800
@@ -511,7 +511,6 @@
         CompileBroker::handle_full_code_cache();
       }
     } else {
-      NOT_PRODUCT(nm->set_has_debug_info(has_debug_info); )
       nm->set_has_unsafe_access(has_unsafe_access);
 
       // Record successful registration.