src/share/vm/opto/optoreg.hpp

Thu, 28 Jun 2012 17:03:16 -0400

author
zgu
date
Thu, 28 Jun 2012 17:03:16 -0400
changeset 3900
d2a62e0f25eb
parent 3138
f6f3bb0ee072
child 4478
a7114d3d712e
permissions
-rw-r--r--

6995781: Native Memory Tracking (Phase 1)
7151532: DCmd for hotspot native memory tracking
Summary: Implementation of native memory tracking phase 1, which tracks VM native memory usage, and related DCmd
Reviewed-by: acorn, coleenp, fparain

duke@435 1 /*
never@3138 2 * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_OPTO_OPTOREG_HPP
stefank@2314 26 #define SHARE_VM_OPTO_OPTOREG_HPP
stefank@2314 27
duke@435 28 //------------------------------OptoReg----------------------------------------
duke@435 29 // We eventually need Registers for the Real World. Registers are essentially
duke@435 30 // non-SSA names. A Register is represented as a number. Non-regular values
duke@435 31 // (e.g., Control, Memory, I/O) use the Special register. The actual machine
duke@435 32 // registers (as described in the ADL file for a machine) start at zero.
duke@435 33 // Stack-slots (spill locations) start at the nest Chunk past the last machine
duke@435 34 // register.
duke@435 35 //
duke@435 36 // Note that stack spill-slots are treated as a very large register set.
duke@435 37 // They have all the correct properties for a Register: not aliased (unique
duke@435 38 // named). There is some simple mapping from a stack-slot register number
duke@435 39 // to the actual location on the stack; this mapping depends on the calling
duke@435 40 // conventions and is described in the ADL.
duke@435 41 //
duke@435 42 // Note that Name is not enum. C++ standard defines that the range of enum
duke@435 43 // is the range of smallest bit-field that can represent all enumerators
duke@435 44 // declared in the enum. The result of assigning a value to enum is undefined
duke@435 45 // if the value is outside the enumeration's valid range. OptoReg::Name is
duke@435 46 // typedef'ed as int, because it needs to be able to represent spill-slots.
duke@435 47 //
duke@435 48 class OptoReg VALUE_OBJ_CLASS_SPEC {
duke@435 49
duke@435 50 friend class C2Compiler;
duke@435 51 public:
duke@435 52 typedef int Name;
duke@435 53 enum {
duke@435 54 // Chunk 0
duke@435 55 Physical = AdlcVMDeps::Physical, // Start of physical regs
duke@435 56 // A few oddballs at the edge of the world
duke@435 57 Special = -2, // All special (not allocated) values
duke@435 58 Bad = -1 // Not a register
duke@435 59 };
duke@435 60
duke@435 61 private:
duke@435 62
duke@435 63 static const VMReg opto2vm[REG_COUNT];
duke@435 64 static Name vm2opto[ConcreteRegisterImpl::number_of_registers];
duke@435 65
duke@435 66 public:
duke@435 67
duke@435 68 // Stack pointer register
duke@435 69 static OptoReg::Name c_frame_pointer;
duke@435 70
duke@435 71
duke@435 72
duke@435 73 // Increment a register number. As in:
duke@435 74 // "for ( OptoReg::Name i; i=Control; i = add(i,1) ) ..."
duke@435 75 static Name add( Name x, int y ) { return Name(x+y); }
duke@435 76
duke@435 77 // (We would like to have an operator+ for RegName, but it is not
duke@435 78 // a class, so this would be illegal in C++.)
duke@435 79
duke@435 80 static void dump( int );
duke@435 81
duke@435 82 // Get the stack slot number of an OptoReg::Name
duke@435 83 static unsigned int reg2stack( OptoReg::Name r) {
duke@435 84 assert( r >= stack0(), " must be");
duke@435 85 return r - stack0();
duke@435 86 }
duke@435 87
duke@435 88 // convert a stack slot number into an OptoReg::Name
duke@435 89 static OptoReg::Name stack2reg( int idx) {
duke@435 90 return Name(stack0() + idx);
duke@435 91 }
duke@435 92
duke@435 93 static bool is_stack(Name n) {
duke@435 94 return n >= stack0();
duke@435 95 }
duke@435 96
duke@435 97 static bool is_valid(Name n) {
duke@435 98 return (n != Bad);
duke@435 99 }
duke@435 100
duke@435 101 static bool is_reg(Name n) {
duke@435 102 return is_valid(n) && !is_stack(n);
duke@435 103 }
duke@435 104
duke@435 105 static VMReg as_VMReg(OptoReg::Name n) {
duke@435 106 if (is_reg(n)) {
duke@435 107 // Must use table, it'd be nice if Bad was indexable...
duke@435 108 return opto2vm[n];
duke@435 109 } else {
duke@435 110 assert(!is_stack(n), "must un warp");
duke@435 111 return VMRegImpl::Bad();
duke@435 112 }
duke@435 113 }
duke@435 114
duke@435 115 // Can un-warp a stack slot or convert a register or Bad
duke@435 116 static VMReg as_VMReg(OptoReg::Name n, int frame_size, int arg_count) {
duke@435 117 if (is_reg(n)) {
duke@435 118 // Must use table, it'd be nice if Bad was indexable...
duke@435 119 return opto2vm[n];
duke@435 120 } else if (is_stack(n)) {
duke@435 121 int stack_slot = reg2stack(n);
duke@435 122 if (stack_slot < arg_count) {
duke@435 123 return VMRegImpl::stack2reg(stack_slot + frame_size);
duke@435 124 }
duke@435 125 return VMRegImpl::stack2reg(stack_slot - arg_count);
duke@435 126 // return return VMRegImpl::stack2reg(reg2stack(OptoReg::add(n, -arg_count)));
duke@435 127 } else {
duke@435 128 return VMRegImpl::Bad();
duke@435 129 }
duke@435 130 }
duke@435 131
duke@435 132 static OptoReg::Name as_OptoReg(VMReg r) {
duke@435 133 if (r->is_stack()) {
duke@435 134 assert(false, "must warp");
duke@435 135 return stack2reg(r->reg2stack());
duke@435 136 } else if (r->is_valid()) {
duke@435 137 // Must use table, it'd be nice if Bad was indexable...
duke@435 138 return vm2opto[r->value()];
duke@435 139 } else {
duke@435 140 return Bad;
duke@435 141 }
duke@435 142 }
duke@435 143
duke@435 144 static OptoReg::Name stack0() {
duke@435 145 return VMRegImpl::stack0->value();
duke@435 146 }
duke@435 147
duke@435 148 static const char* regname(OptoReg::Name n) {
duke@435 149 return as_VMReg(n)->name();
duke@435 150 }
duke@435 151
duke@435 152 };
duke@435 153
duke@435 154 //---------------------------OptoRegPair-------------------------------------------
duke@435 155 // Pairs of 32-bit registers for the allocator.
duke@435 156 // This is a very similar class to VMRegPair. C2 only interfaces with VMRegPair
duke@435 157 // via the calling convention code which is shared between the compilers.
duke@435 158 // Since C2 uses OptoRegs for register allocation it is more efficient to use
duke@435 159 // VMRegPair internally for nodes that can contain a pair of OptoRegs rather
duke@435 160 // than use VMRegPair and continually be converting back and forth. So normally
duke@435 161 // C2 will take in a VMRegPair from the calling convention code and immediately
duke@435 162 // convert them to an OptoRegPair and stay in the OptoReg world. The only over
duke@435 163 // conversion between OptoRegs and VMRegs is for debug info and oopMaps. This
duke@435 164 // is not a high bandwidth spot and so it is not an issue.
duke@435 165 // Note that onde other consequence of staying in the OptoReg world with OptoRegPairs
duke@435 166 // is that there are "physical" OptoRegs that are not representable in the VMReg
duke@435 167 // world, notably flags. [ But by design there is "space" in the VMReg world
duke@435 168 // for such registers they just may not be concrete ]. So if we were to use VMRegPair
duke@435 169 // then the VMReg world would have to have a representation for these registers
duke@435 170 // so that a OptoReg->VMReg->OptoReg would reproduce ther original OptoReg. As it
duke@435 171 // stands if you convert a flag (condition code) to a VMReg you will get VMRegImpl::Bad
duke@435 172 // and converting that will return OptoReg::Bad losing the identity of the OptoReg.
duke@435 173
duke@435 174 class OptoRegPair {
never@3138 175 friend class VMStructs;
duke@435 176 private:
duke@435 177 short _second;
duke@435 178 short _first;
duke@435 179 public:
duke@435 180 void set_bad ( ) { _second = OptoReg::Bad; _first = OptoReg::Bad; }
duke@435 181 void set1 ( OptoReg::Name n ) { _second = OptoReg::Bad; _first = n; }
duke@435 182 void set2 ( OptoReg::Name n ) { _second = n + 1; _first = n; }
duke@435 183 void set_pair( OptoReg::Name second, OptoReg::Name first ) { _second= second; _first= first; }
duke@435 184 void set_ptr ( OptoReg::Name ptr ) {
duke@435 185 #ifdef _LP64
duke@435 186 _second = ptr+1;
duke@435 187 #else
duke@435 188 _second = OptoReg::Bad;
duke@435 189 #endif
duke@435 190 _first = ptr;
duke@435 191 }
duke@435 192
duke@435 193 OptoReg::Name second() const { return _second; }
duke@435 194 OptoReg::Name first() const { return _first; }
duke@435 195 OptoRegPair(OptoReg::Name second, OptoReg::Name first) { _second = second; _first = first; }
duke@435 196 OptoRegPair(OptoReg::Name f) { _second = OptoReg::Bad; _first = f; }
duke@435 197 OptoRegPair() { _second = OptoReg::Bad; _first = OptoReg::Bad; }
duke@435 198 };
stefank@2314 199
stefank@2314 200 #endif // SHARE_VM_OPTO_OPTOREG_HPP

mercurial