src/share/vm/code/location.hpp

Thu, 24 May 2018 18:41:44 +0800

author
aoqi
date
Thu, 24 May 2018 18:41:44 +0800
changeset 8856
ac27a9c85bea
parent 6876
710a3c8b516e
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_CODE_LOCATION_HPP
aoqi@0 26 #define SHARE_VM_CODE_LOCATION_HPP
aoqi@0 27
aoqi@0 28 #include "asm/assembler.hpp"
aoqi@0 29 #include "code/vmreg.hpp"
aoqi@0 30 #include "memory/allocation.hpp"
aoqi@0 31
aoqi@0 32 // A Location describes a concrete machine variable location
aoqi@0 33 // (such as integer or floating point register or a stack-held
aoqi@0 34 // variable). Used when generating debug-information for nmethods.
aoqi@0 35 //
aoqi@0 36 // Encoding:
aoqi@0 37 //
aoqi@0 38 // bits (use low bits for best compression):
aoqi@0 39 // Type: [3..0]
aoqi@0 40 // Where: [4]
aoqi@0 41 // Offset: [31..5]
aoqi@0 42
aoqi@0 43 class Location VALUE_OBJ_CLASS_SPEC {
aoqi@0 44 friend class VMStructs;
aoqi@0 45 public:
aoqi@0 46 enum Where {
aoqi@0 47 on_stack,
aoqi@0 48 in_register
aoqi@0 49 };
aoqi@0 50
aoqi@0 51 enum Type {
aoqi@0 52 invalid, // Invalid location
aoqi@0 53 normal, // Ints, floats, double halves
aoqi@0 54 oop, // Oop (please GC me!)
aoqi@0 55 int_in_long, // Integer held in long register
aoqi@0 56 lng, // Long held in one register
aoqi@0 57 float_in_dbl, // Float held in double register
aoqi@0 58 dbl, // Double held in one register
aoqi@0 59 addr, // JSR return address
aoqi@0 60 narrowoop // Narrow Oop (please GC me!)
aoqi@0 61 };
aoqi@0 62
aoqi@0 63
aoqi@0 64 private:
aoqi@0 65 enum {
aoqi@0 66 TYPE_MASK = (juint) 0x0F,
aoqi@0 67 TYPE_SHIFT = 0,
aoqi@0 68 WHERE_MASK = (juint) 0x10,
aoqi@0 69 WHERE_SHIFT = 4,
aoqi@0 70 OFFSET_MASK = (juint) 0xFFFFFFE0,
aoqi@0 71 OFFSET_SHIFT = 5
aoqi@0 72 };
aoqi@0 73
aoqi@0 74 juint _value;
aoqi@0 75
aoqi@0 76 // Create a bit-packed Location
aoqi@0 77 Location(Where where_, Type type_, unsigned offset_) {
aoqi@0 78 set(where_, type_, offset_);
aoqi@0 79 assert( where () == where_ , "" );
aoqi@0 80 assert( type () == type_ , "" );
aoqi@0 81 assert( offset() == offset_, "" );
aoqi@0 82 }
aoqi@0 83
aoqi@0 84 inline void set(Where where_, Type type_, unsigned offset_) {
aoqi@0 85 _value = (juint) ((where_ << WHERE_SHIFT) |
aoqi@0 86 (type_ << TYPE_SHIFT) |
aoqi@0 87 ((offset_ << OFFSET_SHIFT) & OFFSET_MASK));
aoqi@0 88 }
aoqi@0 89
aoqi@0 90 public:
aoqi@0 91
aoqi@0 92 // Stack location Factory. Offset is 4-byte aligned; remove low bits
aoqi@0 93 static Location new_stk_loc( Type t, int offset ) { return Location(on_stack,t,offset>>LogBytesPerInt); }
aoqi@0 94 // Register location Factory
aoqi@0 95 static Location new_reg_loc( Type t, VMReg reg ) { return Location(in_register, t, reg->value()); }
aoqi@0 96 // Default constructor
aoqi@0 97 Location() { set(on_stack,invalid,0); }
aoqi@0 98
aoqi@0 99 // Bit field accessors
aoqi@0 100 Where where() const { return (Where) ((_value & WHERE_MASK) >> WHERE_SHIFT);}
aoqi@0 101 Type type() const { return (Type) ((_value & TYPE_MASK) >> TYPE_SHIFT); }
aoqi@0 102 unsigned offset() const { return (unsigned) ((_value & OFFSET_MASK) >> OFFSET_SHIFT); }
aoqi@0 103
aoqi@0 104 // Accessors
aoqi@0 105 bool is_register() const { return where() == in_register; }
aoqi@0 106 bool is_stack() const { return where() == on_stack; }
aoqi@0 107
aoqi@0 108 int stack_offset() const { assert(where() == on_stack, "wrong Where"); return offset()<<LogBytesPerInt; }
aoqi@0 109 int register_number() const { assert(where() == in_register, "wrong Where"); return offset() ; }
aoqi@0 110
aoqi@0 111 VMReg reg() const { assert(where() == in_register, "wrong Where"); return VMRegImpl::as_VMReg(offset()) ; }
aoqi@0 112
aoqi@0 113 // Printing
aoqi@0 114 void print_on(outputStream* st) const;
aoqi@0 115
aoqi@0 116 // Serialization of debugging information
aoqi@0 117 Location(DebugInfoReadStream* stream);
aoqi@0 118 void write_on(DebugInfoWriteStream* stream);
aoqi@0 119
aoqi@0 120 // check
aoqi@0 121 static bool legal_offset_in_bytes(int offset_in_bytes);
aoqi@0 122 };
aoqi@0 123
aoqi@0 124 #endif // SHARE_VM_CODE_LOCATION_HPP

mercurial