< prev index next >

src/hotspot/share/c1/c1_LinearScan.cpp

Print this page

  45   // helper macro for short definition of timer
  46   #define TIME_LINEAR_SCAN(timer_name)  TraceTime _block_timer("", _total_timer.timer(LinearScanTimers::timer_name), TimeLinearScan || TimeEachLinearScan, Verbose);
  47 
  48 #else
  49   #define TIME_LINEAR_SCAN(timer_name)
  50 #endif
  51 
  52 #ifdef ASSERT
  53 
  54   // helper macro for short definition of trace-output inside code
  55   #define TRACE_LINEAR_SCAN(level, code)       \
  56     if (TraceLinearScanLevel >= level) {       \
  57       code;                                    \
  58     }
  59 #else
  60   #define TRACE_LINEAR_SCAN(level, code)
  61 #endif
  62 
  63 // Map BasicType to spill size in 32-bit words, matching VMReg's notion of words
  64 #ifdef _LP64
  65 static int type2spill_size[T_CONFLICT+1]={ -1, 0, 0, 0, 1, 1, 1, 2, 1, 1, 1, 2, 2, 2, 0, 2,  1, 2, 1, -1};
  66 #else
  67 static int type2spill_size[T_CONFLICT+1]={ -1, 0, 0, 0, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 0, 1, -1, 1, 1, -1};
  68 #endif
  69 
  70 
  71 // Implementation of LinearScan
  72 
  73 LinearScan::LinearScan(IR* ir, LIRGenerator* gen, FrameMap* frame_map)
  74  : _compilation(ir->compilation())
  75  , _ir(ir)
  76  , _gen(gen)
  77  , _frame_map(frame_map)
  78  , _cached_blocks(*ir->linear_scan_order())
  79  , _num_virtual_regs(gen->max_virtual_register_number())
  80  , _has_fpu_registers(false)
  81  , _num_calls(-1)
  82  , _max_spills(0)
  83  , _unused_spill_slot(-1)
  84  , _intervals(0)   // initialized later with correct length
  85  , _new_intervals_from_allocation(nullptr)
  86  , _sorted_intervals(nullptr)
  87  , _needs_full_resort(false)

 239   if (result > 2000) {
 240     bailout("too many stack slots used");
 241   }
 242 
 243   return result;
 244 }
 245 
 246 void LinearScan::assign_spill_slot(Interval* it) {
 247   // assign the canonical spill slot of the parent (if a part of the interval
 248   // is already spilled) or allocate a new spill slot
 249   if (it->canonical_spill_slot() >= 0) {
 250     it->assign_reg(it->canonical_spill_slot());
 251   } else {
 252     int spill = allocate_spill_slot(type2spill_size[it->type()] == 2);
 253     it->set_canonical_spill_slot(spill);
 254     it->assign_reg(spill);
 255   }
 256 }
 257 
 258 void LinearScan::propagate_spill_slots() {
 259   if (!frame_map()->finalize_frame(max_spills())) {
 260     bailout("frame too large");
 261   }
 262 }
 263 
 264 // create a new interval with a predefined reg_num
 265 // (only used for parent intervals that are created during the building phase)
 266 Interval* LinearScan::create_interval(int reg_num) {
 267   assert(_intervals.at(reg_num) == nullptr, "overwriting existing interval");
 268 
 269   Interval* interval = new Interval(reg_num);
 270   _intervals.at_put(reg_num, interval);
 271 
 272   // assign register number for precolored intervals
 273   if (reg_num < LIR_Opr::vreg_base) {
 274     interval->assign_reg(reg_num);
 275   }
 276   return interval;
 277 }
 278 
 279 // assign a new reg_num to the interval and append it to the list of intervals

2909     int pos = 0;
2910     while (pos < nof_stack) {
2911       Value expression = cur_state->stack_at(pos);
2912       pos += append_scope_value(op_id, expression, expressions);
2913 
2914       assert(expressions->length() == pos, "must match");
2915     }
2916     assert(expressions->length() == cur_state->stack_size(), "wrong number of stack entries");
2917   }
2918 
2919   // describe monitors
2920   int nof_locks = cur_state->locks_size();
2921   if (nof_locks > 0) {
2922     int lock_offset = cur_state->caller_state() != nullptr ? cur_state->caller_state()->total_locks_size() : 0;
2923     monitors = new GrowableArray<MonitorValue*>(nof_locks);
2924     for (int i = 0; i < nof_locks; i++) {
2925       monitors->append(location_for_monitor_index(lock_offset + i));
2926     }
2927   }
2928 
2929   return new IRScopeDebugInfo(cur_scope, cur_state->bci(), locals, expressions, monitors, caller_debug_info);
2930 }
2931 
2932 
2933 void LinearScan::compute_debug_info(CodeEmitInfo* info, int op_id) {
2934   TRACE_LINEAR_SCAN(3, tty->print_cr("creating debug information at op_id %d", op_id));
2935 
2936   IRScope* innermost_scope = info->scope();
2937   ValueStack* innermost_state = info->stack();
2938 
2939   assert(innermost_scope != nullptr && innermost_state != nullptr, "why is it missing?");
2940 
2941   DEBUG_ONLY(check_stack_depth(info, innermost_state->stack_size()));
2942 
2943   if (info->_scope_debug_info == nullptr) {
2944     // compute debug information
2945     info->_scope_debug_info = compute_debug_info_for_scope(op_id, innermost_scope, innermost_state, innermost_state);
2946   } else {
2947     // debug information already set. Check that it is correct from the current point of view
2948     DEBUG_ONLY(assert_equal(info->_scope_debug_info, compute_debug_info_for_scope(op_id, innermost_scope, innermost_state, innermost_state)));
2949   }

  45   // helper macro for short definition of timer
  46   #define TIME_LINEAR_SCAN(timer_name)  TraceTime _block_timer("", _total_timer.timer(LinearScanTimers::timer_name), TimeLinearScan || TimeEachLinearScan, Verbose);
  47 
  48 #else
  49   #define TIME_LINEAR_SCAN(timer_name)
  50 #endif
  51 
  52 #ifdef ASSERT
  53 
  54   // helper macro for short definition of trace-output inside code
  55   #define TRACE_LINEAR_SCAN(level, code)       \
  56     if (TraceLinearScanLevel >= level) {       \
  57       code;                                    \
  58     }
  59 #else
  60   #define TRACE_LINEAR_SCAN(level, code)
  61 #endif
  62 
  63 // Map BasicType to spill size in 32-bit words, matching VMReg's notion of words
  64 #ifdef _LP64
  65 static int type2spill_size[T_CONFLICT+1]={ -1, 0, 0, 0, 1, 1, 1, 2, 1, 1, 1, 2, 2, 2, 2, 0, 2,  1, 2, 1, -1};
  66 #else
  67 static int type2spill_size[T_CONFLICT+1]={ -1, 0, 0, 0, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 0, 1, -1, 1, 1, -1};
  68 #endif
  69 
  70 
  71 // Implementation of LinearScan
  72 
  73 LinearScan::LinearScan(IR* ir, LIRGenerator* gen, FrameMap* frame_map)
  74  : _compilation(ir->compilation())
  75  , _ir(ir)
  76  , _gen(gen)
  77  , _frame_map(frame_map)
  78  , _cached_blocks(*ir->linear_scan_order())
  79  , _num_virtual_regs(gen->max_virtual_register_number())
  80  , _has_fpu_registers(false)
  81  , _num_calls(-1)
  82  , _max_spills(0)
  83  , _unused_spill_slot(-1)
  84  , _intervals(0)   // initialized later with correct length
  85  , _new_intervals_from_allocation(nullptr)
  86  , _sorted_intervals(nullptr)
  87  , _needs_full_resort(false)

 239   if (result > 2000) {
 240     bailout("too many stack slots used");
 241   }
 242 
 243   return result;
 244 }
 245 
 246 void LinearScan::assign_spill_slot(Interval* it) {
 247   // assign the canonical spill slot of the parent (if a part of the interval
 248   // is already spilled) or allocate a new spill slot
 249   if (it->canonical_spill_slot() >= 0) {
 250     it->assign_reg(it->canonical_spill_slot());
 251   } else {
 252     int spill = allocate_spill_slot(type2spill_size[it->type()] == 2);
 253     it->set_canonical_spill_slot(spill);
 254     it->assign_reg(spill);
 255   }
 256 }
 257 
 258 void LinearScan::propagate_spill_slots() {
 259   if (!frame_map()->finalize_frame(max_spills(), compilation()->needs_stack_repair())) {
 260     bailout("frame too large");
 261   }
 262 }
 263 
 264 // create a new interval with a predefined reg_num
 265 // (only used for parent intervals that are created during the building phase)
 266 Interval* LinearScan::create_interval(int reg_num) {
 267   assert(_intervals.at(reg_num) == nullptr, "overwriting existing interval");
 268 
 269   Interval* interval = new Interval(reg_num);
 270   _intervals.at_put(reg_num, interval);
 271 
 272   // assign register number for precolored intervals
 273   if (reg_num < LIR_Opr::vreg_base) {
 274     interval->assign_reg(reg_num);
 275   }
 276   return interval;
 277 }
 278 
 279 // assign a new reg_num to the interval and append it to the list of intervals

2909     int pos = 0;
2910     while (pos < nof_stack) {
2911       Value expression = cur_state->stack_at(pos);
2912       pos += append_scope_value(op_id, expression, expressions);
2913 
2914       assert(expressions->length() == pos, "must match");
2915     }
2916     assert(expressions->length() == cur_state->stack_size(), "wrong number of stack entries");
2917   }
2918 
2919   // describe monitors
2920   int nof_locks = cur_state->locks_size();
2921   if (nof_locks > 0) {
2922     int lock_offset = cur_state->caller_state() != nullptr ? cur_state->caller_state()->total_locks_size() : 0;
2923     monitors = new GrowableArray<MonitorValue*>(nof_locks);
2924     for (int i = 0; i < nof_locks; i++) {
2925       monitors->append(location_for_monitor_index(lock_offset + i));
2926     }
2927   }
2928 
2929   return new IRScopeDebugInfo(cur_scope, cur_state->bci(), locals, expressions, monitors, caller_debug_info, cur_state->should_reexecute());
2930 }
2931 
2932 
2933 void LinearScan::compute_debug_info(CodeEmitInfo* info, int op_id) {
2934   TRACE_LINEAR_SCAN(3, tty->print_cr("creating debug information at op_id %d", op_id));
2935 
2936   IRScope* innermost_scope = info->scope();
2937   ValueStack* innermost_state = info->stack();
2938 
2939   assert(innermost_scope != nullptr && innermost_state != nullptr, "why is it missing?");
2940 
2941   DEBUG_ONLY(check_stack_depth(info, innermost_state->stack_size()));
2942 
2943   if (info->_scope_debug_info == nullptr) {
2944     // compute debug information
2945     info->_scope_debug_info = compute_debug_info_for_scope(op_id, innermost_scope, innermost_state, innermost_state);
2946   } else {
2947     // debug information already set. Check that it is correct from the current point of view
2948     DEBUG_ONLY(assert_equal(info->_scope_debug_info, compute_debug_info_for_scope(op_id, innermost_scope, innermost_state, innermost_state)));
2949   }
< prev index next >