registerMap.hpp revision 1472:c18cbe5936b8
1/*
2 * Copyright (c) 2002, 2007, 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
25class JavaThread;
26
27//
28// RegisterMap
29//
30// A companion structure used for stack traversal. The RegisterMap contains
31// misc. information needed in order to do correct stack traversal of stack
32// frames.  Hence, it must always be passed in as an argument to
33// frame::sender(RegisterMap*).
34//
35// In particular,
36//   1) It provides access to the thread for which the stack belongs.  The
37//      thread object is needed in order to get sender of a deoptimized frame.
38//
39//   2) It is used to pass information from a callee frame to its caller
40//      frame about how the frame should be traversed.  This is used to let
41//      the caller frame take care of calling oops-do of out-going
42//      arguments, when the callee frame is not instantiated yet.  This
43//      happens, e.g., when a compiled frame calls into
44//      resolve_virtual_call.  (Hence, it is critical that the same
45//      RegisterMap object is used for the entire stack walk.  Normally,
46//      this is hidden by using the StackFrameStream.)  This is used when
47//      doing follow_oops and oops_do.
48//
49//   3) The RegisterMap keeps track of the values of callee-saved registers
50//      from frame to frame (hence, the name).  For some stack traversal the
51//      values of the callee-saved registers does not matter, e.g., if you
52//      only need the static properies such as frame type, pc, and such.
53//      Updating of the RegisterMap can be turned off by instantiating the
54//      register map as: RegisterMap map(thread, false);
55
56class RegisterMap : public StackObj {
57 public:
58    typedef julong LocationValidType;
59  enum {
60    reg_count = ConcreteRegisterImpl::number_of_registers,
61    location_valid_type_size = sizeof(LocationValidType)*8,
62    location_valid_size = (reg_count+location_valid_type_size-1)/location_valid_type_size
63  };
64 private:
65  intptr_t*    _location[reg_count];    // Location of registers (intptr_t* looks better than address in the debugger)
66  LocationValidType _location_valid[location_valid_size];
67  bool        _include_argument_oops;   // Should include argument_oop marked locations for compiler
68  JavaThread* _thread;                  // Reference to current thread
69  bool        _update_map;              // Tells if the register map need to be
70                                        // updated when traversing the stack
71
72#ifdef ASSERT
73  void check_location_valid();
74#else
75  void check_location_valid() {}
76#endif
77
78 public:
79  debug_only(intptr_t* _update_for_id;) // Assert that RegisterMap is not updated twice for same frame
80  RegisterMap(JavaThread *thread, bool update_map = true);
81  RegisterMap(const RegisterMap* map);
82
83  address location(VMReg reg) const {
84    int index = reg->value() / location_valid_type_size;
85    assert(0 <= reg->value() && reg->value() < reg_count, "range check");
86    assert(0 <= index && index < location_valid_size, "range check");
87    if (_location_valid[index] & ((LocationValidType)1 << (reg->value() % location_valid_type_size))) {
88      return (address) _location[reg->value()];
89    } else {
90      return pd_location(reg);
91    }
92  }
93
94  void set_location(VMReg reg, address loc) {
95    int index = reg->value() / location_valid_type_size;
96    assert(0 <= reg->value() && reg->value() < reg_count, "range check");
97    assert(0 <= index && index < location_valid_size, "range check");
98    assert(_update_map, "updating map that does not need updating");
99    _location[reg->value()] = (intptr_t*) loc;
100    _location_valid[index] |= ((LocationValidType)1 << (reg->value() % location_valid_type_size));
101    check_location_valid();
102  }
103
104  // Called by an entry frame.
105  void clear();
106
107  bool include_argument_oops() const      { return _include_argument_oops; }
108  void set_include_argument_oops(bool f)  { _include_argument_oops = f; }
109
110  JavaThread *thread() const { return _thread; }
111  bool update_map()    const { return _update_map; }
112
113  void print_on(outputStream* st) const;
114  void print() const;
115
116  // the following contains the definition of pd_xxx methods
117# include "incls/_registerMap_pd.hpp.incl"
118};
119