Wed, 02 Jun 2010 22:45:42 -0700
Merge
1 /*
2 * Copyright (c) 1997, 2008, 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 */
25 // A Location describes a concrete machine variable location
26 // (such as integer or floating point register or a stack-held
27 // variable). Used when generating debug-information for nmethods.
28 //
29 // Encoding:
30 //
31 // bits (use low bits for best compression):
32 // Type: [3..0]
33 // Where: [4]
34 // Offset: [31..5]
36 class Location VALUE_OBJ_CLASS_SPEC {
37 friend class VMStructs;
38 public:
39 enum Where {
40 on_stack,
41 in_register
42 };
44 enum Type {
45 invalid, // Invalid location
46 normal, // Ints, floats, double halves
47 oop, // Oop (please GC me!)
48 int_in_long, // Integer held in long register
49 lng, // Long held in one register
50 float_in_dbl, // Float held in double register
51 dbl, // Double held in one register
52 addr, // JSR return address
53 narrowoop // Narrow Oop (please GC me!)
54 };
57 private:
58 enum {
59 TYPE_MASK = (juint) 0x0F,
60 TYPE_SHIFT = 0,
61 WHERE_MASK = (juint) 0x10,
62 WHERE_SHIFT = 4,
63 OFFSET_MASK = (juint) 0xFFFFFFE0,
64 OFFSET_SHIFT = 5
65 };
67 juint _value;
69 // Create a bit-packed Location
70 Location(Where where_, Type type_, unsigned offset_) {
71 set(where_, type_, offset_);
72 assert( where () == where_ , "" );
73 assert( type () == type_ , "" );
74 assert( offset() == offset_, "" );
75 }
77 inline void set(Where where_, Type type_, unsigned offset_) {
78 _value = (juint) ((where_ << WHERE_SHIFT) |
79 (type_ << TYPE_SHIFT) |
80 ((offset_ << OFFSET_SHIFT) & OFFSET_MASK));
81 }
83 public:
85 // Stack location Factory. Offset is 4-byte aligned; remove low bits
86 static Location new_stk_loc( Type t, int offset ) { return Location(on_stack,t,offset>>LogBytesPerInt); }
87 // Register location Factory
88 static Location new_reg_loc( Type t, VMReg reg ) { return Location(in_register, t, reg->value()); }
89 // Default constructor
90 Location() { set(on_stack,invalid,0); }
92 // Bit field accessors
93 Where where() const { return (Where) ((_value & WHERE_MASK) >> WHERE_SHIFT);}
94 Type type() const { return (Type) ((_value & TYPE_MASK) >> TYPE_SHIFT); }
95 unsigned offset() const { return (unsigned) ((_value & OFFSET_MASK) >> OFFSET_SHIFT); }
97 // Accessors
98 bool is_register() const { return where() == in_register; }
99 bool is_stack() const { return where() == on_stack; }
101 int stack_offset() const { assert(where() == on_stack, "wrong Where"); return offset()<<LogBytesPerInt; }
102 int register_number() const { assert(where() == in_register, "wrong Where"); return offset() ; }
104 VMReg reg() const { assert(where() == in_register, "wrong Where"); return VMRegImpl::as_VMReg(offset()) ; }
106 // Printing
107 void print_on(outputStream* st) const;
109 // Serialization of debugging information
110 Location(DebugInfoReadStream* stream);
111 void write_on(DebugInfoWriteStream* stream);
113 // check
114 static bool legal_offset_in_bytes(int offset_in_bytes);
115 };