10546
|
1 |
/*
|
|
2 |
* Copyright (c) 2011, 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_VM_OOPS_FIELDINFO_HPP
|
|
26 |
#define SHARE_VM_OOPS_FIELDINFO_HPP
|
|
27 |
|
|
28 |
#include "oops/typeArrayOop.hpp"
|
|
29 |
#include "classfile/vmSymbols.hpp"
|
|
30 |
|
|
31 |
// This class represents the field information contained in the fields
|
|
32 |
// array of an instanceKlass. Currently it's laid on top an array of
|
|
33 |
// Java shorts but in the future it could simply be used as a real
|
|
34 |
// array type. FieldInfo generally shouldn't be used directly.
|
|
35 |
// Fields should be queried either through instanceKlass or through
|
|
36 |
// the various FieldStreams.
|
|
37 |
class FieldInfo VALUE_OBJ_CLASS_SPEC {
|
|
38 |
friend class fieldDescriptor;
|
|
39 |
friend class JavaFieldStream;
|
|
40 |
friend class ClassFileParser;
|
|
41 |
|
|
42 |
public:
|
|
43 |
// fields
|
|
44 |
// Field info extracted from the class file and stored
|
|
45 |
// as an array of 7 shorts
|
|
46 |
enum FieldOffset {
|
|
47 |
access_flags_offset = 0,
|
|
48 |
name_index_offset = 1,
|
|
49 |
signature_index_offset = 2,
|
|
50 |
initval_index_offset = 3,
|
|
51 |
low_offset = 4,
|
|
52 |
high_offset = 5,
|
|
53 |
generic_signature_offset = 6,
|
|
54 |
field_slots = 7
|
|
55 |
};
|
|
56 |
|
|
57 |
private:
|
|
58 |
u2 _shorts[field_slots];
|
|
59 |
|
|
60 |
void set_name_index(u2 val) { _shorts[name_index_offset] = val; }
|
|
61 |
void set_signature_index(u2 val) { _shorts[signature_index_offset] = val; }
|
|
62 |
void set_initval_index(u2 val) { _shorts[initval_index_offset] = val; }
|
|
63 |
void set_generic_signature_index(u2 val) { _shorts[generic_signature_offset] = val; }
|
|
64 |
|
|
65 |
u2 name_index() const { return _shorts[name_index_offset]; }
|
|
66 |
u2 signature_index() const { return _shorts[signature_index_offset]; }
|
|
67 |
u2 initval_index() const { return _shorts[initval_index_offset]; }
|
|
68 |
u2 generic_signature_index() const { return _shorts[generic_signature_offset]; }
|
|
69 |
|
|
70 |
public:
|
|
71 |
static FieldInfo* from_field_array(typeArrayOop fields, int index) {
|
|
72 |
return ((FieldInfo*)fields->short_at_addr(index * field_slots));
|
|
73 |
}
|
|
74 |
|
|
75 |
void initialize(u2 access_flags,
|
|
76 |
u2 name_index,
|
|
77 |
u2 signature_index,
|
|
78 |
u2 initval_index,
|
|
79 |
u2 generic_signature_index,
|
|
80 |
u4 offset) {
|
|
81 |
_shorts[access_flags_offset] = access_flags;
|
|
82 |
_shorts[name_index_offset] = name_index;
|
|
83 |
_shorts[signature_index_offset] = signature_index;
|
|
84 |
_shorts[initval_index_offset] = initval_index;
|
|
85 |
_shorts[generic_signature_offset] = generic_signature_index;
|
|
86 |
set_offset(offset);
|
|
87 |
}
|
|
88 |
|
|
89 |
u2 access_flags() const { return _shorts[access_flags_offset]; }
|
|
90 |
u4 offset() const { return build_int_from_shorts(_shorts[low_offset], _shorts[high_offset]); }
|
|
91 |
|
|
92 |
Symbol* name(constantPoolHandle cp) const {
|
|
93 |
int index = name_index();
|
|
94 |
if (is_internal()) {
|
|
95 |
return lookup_symbol(index);
|
|
96 |
}
|
|
97 |
return cp->symbol_at(index);
|
|
98 |
}
|
|
99 |
|
|
100 |
Symbol* signature(constantPoolHandle cp) const {
|
|
101 |
int index = signature_index();
|
|
102 |
if (is_internal()) {
|
|
103 |
return lookup_symbol(index);
|
|
104 |
}
|
|
105 |
return cp->symbol_at(index);
|
|
106 |
}
|
|
107 |
|
|
108 |
Symbol* generic_signature(constantPoolHandle cp) const {
|
|
109 |
int index = generic_signature_index();
|
|
110 |
if (index == 0) {
|
|
111 |
return NULL;
|
|
112 |
}
|
|
113 |
return cp->symbol_at(index);
|
|
114 |
}
|
|
115 |
|
|
116 |
void set_access_flags(u2 val) { _shorts[access_flags_offset] = val; }
|
|
117 |
void set_offset(u4 val) {
|
|
118 |
_shorts[low_offset] = extract_low_short_from_int(val);
|
|
119 |
_shorts[high_offset] = extract_high_short_from_int(val);
|
|
120 |
}
|
|
121 |
|
|
122 |
bool is_internal() const {
|
|
123 |
return (access_flags() & JVM_ACC_FIELD_INTERNAL) != 0;
|
|
124 |
}
|
|
125 |
|
|
126 |
Symbol* lookup_symbol(int symbol_index) const {
|
|
127 |
assert(is_internal(), "only internal fields");
|
|
128 |
return vmSymbols::symbol_at((vmSymbols::SID)symbol_index);
|
|
129 |
}
|
|
130 |
};
|
|
131 |
|
|
132 |
#endif // SHARE_VM_OOPS_FIELDINFO_HPP
|