1 /*
  2  * Copyright (c) 2002, 2021, 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 SHARE_RUNTIME_REGISTERMAP_HPP
 26 #define SHARE_RUNTIME_REGISTERMAP_HPP
 27 
 28 #include "code/vmreg.hpp"


 29 #include "utilities/globalDefinitions.hpp"
 30 #include "utilities/macros.hpp"
 31 
 32 class JavaThread;
 33 
 34 //
 35 // RegisterMap
 36 //
 37 // A companion structure used for stack traversal. The RegisterMap contains
 38 // misc. information needed in order to do correct stack traversal of stack
 39 // frames.  Hence, it must always be passed in as an argument to
 40 // frame::sender(RegisterMap*).
 41 //
 42 // In particular,
 43 //   1) It provides access to the thread for which the stack belongs.  The
 44 //      thread object is needed in order to get sender of a deoptimized frame.
 45 //
 46 //   2) It is used to pass information from a callee frame to its caller
 47 //      frame about how the frame should be traversed.  This is used to let
 48 //      the caller frame take care of calling oops-do of out-going
 49 //      arguments, when the callee frame is not instantiated yet.  This
 50 //      happens, e.g., when a compiled frame calls into
 51 //      resolve_virtual_call.  (Hence, it is critical that the same
 52 //      RegisterMap object is used for the entire stack walk.  Normally,
 53 //      this is hidden by using the StackFrameStream.)  This is used when
 54 //      doing follow_oops and oops_do.
 55 //
 56 //   3) The RegisterMap keeps track of the values of callee-saved registers
 57 //      from frame to frame (hence, the name).  For some stack traversal the
 58 //      values of the callee-saved registers does not matter, e.g., if you
 59 //      only need the static properties such as frame type, pc, and such.
 60 //      Updating of the RegisterMap can be turned off by instantiating the
 61 //      register map as: RegisterMap map(thread, false);
 62 
 63 class RegisterMap : public StackObj {
 64  public:
 65     typedef julong LocationValidType;
 66   enum {
 67     reg_count = ConcreteRegisterImpl::number_of_registers,
 68     location_valid_type_size = sizeof(LocationValidType)*8,
 69     location_valid_size = (reg_count+location_valid_type_size-1)/location_valid_type_size
 70   };
 71  private:
 72   intptr_t*    _location[reg_count];    // Location of registers (intptr_t* looks better than address in the debugger)
 73   LocationValidType _location_valid[location_valid_size];
 74   bool        _include_argument_oops;   // Should include argument_oop marked locations for compiler
 75   JavaThread* _thread;                  // Reference to current thread


 76   bool        _update_map;              // Tells if the register map need to be
 77                                         // updated when traversing the stack
 78   bool        _process_frames;          // Should frames be processed by stack watermark barriers?



 79 
 80 #ifdef ASSERT
 81   void check_location_valid();
 82 #else
 83   void check_location_valid() {}
 84 #endif
 85 
 86  public:
 87   debug_only(intptr_t* _update_for_id;) // Assert that RegisterMap is not updated twice for same frame
 88   RegisterMap(JavaThread *thread, bool update_map = true, bool process_frames = true);

 89   RegisterMap(const RegisterMap* map);
 90 
 91   address location(VMReg reg) const {
 92     int index = reg->value() / location_valid_type_size;
 93     assert(0 <= reg->value() && reg->value() < reg_count, "range check");
 94     assert(0 <= index && index < location_valid_size, "range check");
 95     if (_location_valid[index] & ((LocationValidType)1 << (reg->value() % location_valid_type_size))) {
 96       return (address) _location[reg->value()];
 97     } else {
 98       return pd_location(reg);
 99     }
100   }
101 
102   address location(VMReg base_reg, int slot_idx) const {
103     if (slot_idx > 0) {
104       return pd_location(base_reg, slot_idx);
105     } else {
106       return location(base_reg);










107     }
108   }
109 
110   void set_location(VMReg reg, address loc) {
111     int index = reg->value() / location_valid_type_size;
112     assert(0 <= reg->value() && reg->value() < reg_count, "range check");
113     assert(0 <= index && index < location_valid_size, "range check");
114     assert(_update_map, "updating map that does not need updating");
115     _location[reg->value()] = (intptr_t*) loc;
116     _location_valid[index] |= ((LocationValidType)1 << (reg->value() % location_valid_type_size));
117     check_location_valid();
118   }
119 
120   // Called by an entry frame.
121   void clear();
122 
123   bool include_argument_oops() const      { return _include_argument_oops; }
124   void set_include_argument_oops(bool f)  { _include_argument_oops = f; }
125 
126   JavaThread *thread()  const { return _thread; }
127   bool update_map()     const { return _update_map; }
128   bool process_frames() const { return _process_frames; }









129 
130   void print_on(outputStream* st) const;
131   void print() const;
132 







133   // the following contains the definition of pd_xxx methods
134 #include CPU_HEADER(registerMap)
135 
136 };
137 
138 #endif // SHARE_RUNTIME_REGISTERMAP_HPP
--- EOF ---